I was making a small program to number the lines in a text file to print.
I am just starting to learn C, so don't flame me.
The program takes in a file and creates an output file with the lines numbered. Since if I was to print this, the letters must be stopped somewhere, so I used fgets() with the second buffer parameter. The program is also supposed to number the new line created by this method.
For example:
aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb =
1 aaaaaaaaaaaaaaaaaaaaaaaaaaaa
2 bbbbbbbbbbbbbbbbbbbbbb
I try to check for the '\n' newline character on the last useful character in the string to determine whether I should put one in, but the check never turns up positive.
As I understand it,
char string[5] = "BLUE"
string[4] == '\0'
string[3] == E
Is that correct? If so, why isn't my program working?
I am just starting to learn C, so don't flame me.
The program takes in a file and creates an output file with the lines numbered. Since if I was to print this, the letters must be stopped somewhere, so I used fgets() with the second buffer parameter. The program is also supposed to number the new line created by this method.
For example:
aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb =
1 aaaaaaaaaaaaaaaaaaaaaaaaaaaa
2 bbbbbbbbbbbbbbbbbbbbbb
I try to check for the '\n' newline character on the last useful character in the string to determine whether I should put one in, but the check never turns up positive.
As I understand it,
char string[5] = "BLUE"
string[4] == '\0'
string[3] == E
Is that correct? If so, why isn't my program working?