捞一捞大一c语言新生吧


#include <stdio.h>
#include <string.h>
int main()
{ FILE *p;
      char ch;
   p=fopen("abc.txt","w");
ch=fgetc(stdin);
while(ch!= '#')
{ fputc(ch,p);
ch=fgetc(stdin);
}
return 0;}

这段代码不知道哪里有问题

没什么问题啊

img

??有什么问题
我这边是正常的啊

试试这个?

#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
 
    FILE *fp = fopen("abc.txt", "rb");
    char c ;
    while(c!=EOF)
    {
        c = fgetc (fp);
        printf("%c",c);
    }
    //测试了是可以打印文件全部内容的
    return 0;
}

单单写入文件的话这代码没啥问题啊:

#include <stdio.h>
#include <string.h>
int main()
{ FILE *p;
      char ch;
   p=fopen("abc.txt","w");
ch=fgetc(stdin);
while(ch!= '#')
{ fputc(ch,p);
ch=fgetc(stdin);
}
return 0;
}

写入12345:

img


如果想实现其他的,可以修改 p=fopen("abc.txt","w"); 这一句中的w部分以及while(ch!= '#')while循环的条件部分。
希望对题主有所帮助,望采纳!!

不好意思😅,打扰大家了,代码没问题,不好意思不好意思😬