저는 초보자 C 프로그래머이고 프로그램에서 for 루프에 문제가 있습니다. 루프는 문자 "A"에서 문자 "A"로 문자를 생성하지만 루프는 멈추지 않습니다 편지 'Z'에서 계속 무한정 계속됩니다. 누군가 나를 도울 수 있습니까? 사전for 루프는 테스트 표현식을 무시합니다
#include <stdio.h>
#include <stdlib.h>
FILE * fptr;
int main()
{
char letter;
int i;
fptr = fopen("C:\\Users\\Wim\\Documents\\C\\random read write to
file\\letters.txt", "w+");
if (fptr == 0)
{
printf("There was a error while opening the file! ");
exit(1);
}
for (letter = 'A'; letter <= 'Z'; letter++)//This is the offending part of the code!
{
fputc(letter, fptr);
}
puts ("You just wrote the letters A through Z");
fseek(fptr, -1, SEEK_END);
printf("Here is the file backwards :\n");
for (i= 26; i > 0;i++)
{
letter = fgetc(fptr);
fseek(fptr, -2, SEEK_CUR);
printf("The next letter is %c .\n", letter);
}
fclose(fptr);
return 0;
}
를 작성합니다있을가? – Barmar
@Barmar 디렉토리 이름과 줄 바꿈에 공백이있는 부작용이 있다고 생각합니다. – TerryG
SO는 코드 블록에서 줄 바꿈을 수행하지 않습니다. 잘하면 그는 자신의 프로그램 소스를 편집하기 위해 워드 프로세서를 사용하지 않기를 희망합니다. – Barmar