ファイルを読み取って、すべての文字を対応する ASCII テーブルの 1 つ上の文字に置き換えようとしています。ファイルを適切に開きますが、最初の文字を読み続けます。
int main(int argc, char * argv[])
{
FILE *input;
input = fopen(argv[2], "r+");
if (!input)
{
fprintf(stderr, "Unable to open file %s", argv[2]);
return -1;
}
char ch;
fpos_t * pos;
while( (ch = fgetc(input)) != EOF)
{
printf("%c\n",ch);
fgetpos (input, pos);
fsetpos(input, pos-1);
fputc(ch+1, input);
}
fclose(input);
return 1;
}
テキストファイルは
abc
def
ghi
fgetpos と fsetpos が原因だと確信していますが、それを削除すると、ファイルの最後に文字が追加され、次の fgetc は EOF を返して終了します。