1

text.txt ファイルには、「Apples are red.guavas are green.lemons are yellow」のような行があります。新しい行の最初の文字が必要です(グアバでは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);
}
4

1 に答える 1

1

更新用に開いているファイル (「+」記号を含むもの) で、入力操作と出力操作の両方が許可されている場合、書き込み操作とその後の書き込み操作の間に、ストリームをフラッシュ (fflush) または再配置 (fseek、fsetpos、rewind) する必要があります。読み取り操作、またはファイルの終わりに達しなかった読み取り操作とそれに続く書き込み操作。

行の前後の両方でftellanfを使用して、例を機能させました。fseek

fputc(toupper(c),p);
于 2013-10-27T08:16:56.150 に答える