파일입출력에 관해서 질문
올리브
#include stdio.h
#include stdlib.h
int main(void)
{
char chr[10];
FILE *fp;
fp=fopen(temp1.txt,r);
if(fp==NULL)
{
printf(file open에 오류 발생);
exit(1);
}
while(!feof(fp))
{
fgets(chr,10,fp);
printf(%c,chr);
FILE *fp1;
char chr1[10];
fp1=fopen(temp2.txt,w);
if(fp1==NULL)
{
printf(File open에 오류 발생);
exit(1);
}
while(!feof(fp1))
{
fgets(chr1,10,fp1);
printf(%s,chr1);
}
fclose(fp1);
}
fclose(fp);
return 0;
}
temp1.txt에서 입력받아 temp2.txt로 저장하려고합니다.
그런데 뭐 작동은되는데 빌드시켜 보면 이상한한자가 수없이 무한반복이되고 정작 temp2.txt에는 아무것도 저장이되지를 않네요..
어디를 잘못했나요? ㅠㅠ
-
그녀는귀여웠다
고쳐봤는데 일단 build로 temp1.txt내용은 나오나... 응용프로그램오류가뜨네요 ㅠㅠ
-
돌심보
while(!feof(fp))
\t\t{
\t\t\tchr1=getc(fp);
\t\t\tprintf(\%s\ -
네코
fp1을 \w\로 열었는데 fgets()를 쓰네요.
-
불꾼
흠 %s로 고쳐도 한자무한반복/temp2.txt에는 아무것도 저장이 되지를않네요 ㅠㅠ
-
혁민
while(!feof(fp))
{
fgets(chr,10,fp);
printf(\%c\