在 text.txt 文件中,我有一些行,例如“苹果是红色的。番石榴是绿色的。柠檬是黄色的”。我希望新行中的第一个字母(番石榴中的 g,柠檬中的 l 大写)。但文件中的输出是相同的......
#include<stdio.h>
main()
{
FILE *p;
char c;
int i;
int end_of_line=0;
p=fopen("text.txt","r+");//opening file for reading & writing.
while(c!=EOF)
{
c=fgetc(p);
if(end_of_line==1) // if it is a new line
if (islower(c)!=0) // and if the first letter is small
fputc(toupper(c),p); //change the small to capital
if(c=='.')
end_of_line=1;
else
end_of_line=0;
}
fseek( p, 0, SEEK_SET ); //setting the file pointer to the start of file
while((c=fgetc(p))!=EOF)
printf("%c",c);
fclose(p);
}