Hello guys I have this question for code C: Read the input data(input02.txt) contain 5 strings, then write to new file the length of each string. Strings in file:
Five little
Monkeys jumping
On the bed
One fell off
And bumped his head
Here is my code:
#include <stdio.h>
#include <string.h>
int main(){
char s[100];
int m,c=1;
FILE *fin,*fout;
fin = fopen("input02.txt", "r");
fout = fopen("length.txt", "w");
if (fin!=NULL){
while(!feof(fin)){
fgets(s, 100, fin);
m=strlen(s);
while(c<6){
fprintf(fout,"Length of %d string: %d\n",c,m);
c++;
}
}
fclose(fin);
fclose(fout);
}
return 0;
}
But the output in the length.txt file show like this:
Length of 1 string: 12
Length of 2 string: 12
Length of 3 string: 12
Length of 4 string: 12
Length of 5 string: 12
Can I get some help, ty