#include <stdio.h>
int main()
{
FILE *fp;
int i;
int pos;
fp=fopen("test.txt","r+");
fseek(fp,0,SEEK_END);
pos=ftell(fp);
char ch[pos-1];
fseek(fp,0,SEEK_SET);
ch[0]=ch[0]-32;
i=0;
while(ch[i]=fgetc(fp)!=EOF){
if(ch[i]!=' '){
fseek(fp,1,SEEK_CUR);
i++;
}
else{
fseek(fp,1,SEEK_CUR);
i++;
ch[i]=fgetc(fp);
ch[i]=ch[i]-32;
fprintf(fp,"%c",ch[i]);
}
}
fclose(fp);
}
I want to make C program that capitalizes the first characters of the words in the file. But when I run this code .txt file get wrong. Is usage of fgetc() wrong? where is my fault for this question ? And is fscanf moving cursor ?