Reading a file using fgets
Hey all,
For a few days now I've been trying on and off to figure out a problem while using fgets, and I can't seem to crack it. The issue is I want to use fgets to read a line, dump that output into a char array, and read the array character by character. However, when I try to do so, the output I get instead is the string from that character onwards.
Here's a tiny bit of code I wrote specifically to test this:
Code:
int main()
{
FILE *infile;
char buffer[25];
infile = fopen("testfile", "r");
fgets(buffer, 50, infile);
puts(&buffer[1]);
}
testfile contains a single line: 'This is a test'. The output of this code is 'his is a test', or, in other words, the char array from the first index onwards. I know I'm probably doing something wrong that's rather simple, but I can't seem to get it to work, and I would be very grateful for any help.