謝謝



#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE*fp;
char ch,filename[20];
printf("please input the filename you want to write:");
scanf("%s",filename);
if( !(fp==fopen(filename,"wt+")) );
{
printf("cannot open the file!\n");
exit(0);
}
printf("please input the sentences you want to write:");
ch=getchar();
ch=getchar();
while( ch!=EOF )
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
}

uj5u.com熱心網友回復:
#include<stdio.h>
#include<stdlib.h>
//void main()
int main()
{
FILE*fp;
char filename[20];
int ch; //定義為int,這樣才能與EOF比較
printf("please input the filename you want to write:");
scanf("%s",filename);
//if( !(fp==fopen(filename,"wt+")) ); //為啥多一個分號, 為啥用==
if(!(fp=fopen(filename,"wt+")))
{
printf("cannot open the file!\n");
exit(0);
}
printf("please input the sentences you want to write:");
ch = getchar();
ch = getchar();
while( ch!=EOF )
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
return 0;
}
供參考~
uj5u.com熱心網友回復:
謝謝~~









uj5u.com熱心網友回復:
希望對你有幫助:https://blog.csdn.net/it_xiangqiang/category_10581430.html希望對你有幫助:https://blog.csdn.net/it_xiangqiang/category_10768339.html
uj5u.com熱心網友回復:
謝謝


轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/283343.html
標籤:C語言
上一篇:問個題