Hi,
I have written a program that copies one file to another while making format changes to some lines
The relevant part of the code is the following"
while(fgets (cbuff, 80, f1)!= NULL)
{
if ( (isdigit(cbuff[5])) && (isdigit(cbuff[11])) && (isdigit(cbuff[17])) )
{
strncpy (c1, cbuff+1, 5);
c1[5] = '\0';
strncpy (c2, cbuff+7, 5);
c2[5] = '\0';
strncpy (c3, cbuff+13, 5);
c3[5] = '\0';
strncpy (c4, cbuff+21, 2);
c4[2] = '\0';
fprintf(f2,"%s%s%s%s\n", c1, c2, c3, c4);
}
else
{
fputs(cbuff, f2);
}
}
The program works but does the following:
Input:
1 1 2 1
2 1 4 1
3 2 3 2
4 2 5 1
5 3 6 1
6 3 7 1
Output:
1 1 2 1
2 1 4 1
3 2 3 2
4 2 5 1
5 3 6 1
6 3 7 1
3 7 1
The program outputs an additional line with values of string c2, c3 and c4. I dont understand why this is happening?
How can i get rid of this additional line ?
Thanks in advance.