#include
void main()
{
FILE *fp;
char ch;
if((fp = fopen("test.txt","w"))==NULL)
{
printf("open file failed!\n");
return ;
}
while((ch=getchar())!='#')
{
fputc(ch,fp);
putchar(ch);
}
printf("\n");
fclose(fp);
}
#include
#include
#include
main()
{
FILE *fp;
char c;
if((fp=fopen("test.txt","w"))==NULL)
{ printf("can not open this file\n");
exit(0);
}
else
{
printf("input string,ending with #:\n");
c=getchar();
while(c!='#')
{
fputc(c,fp);
putchar(c);
c=getchar();
}
fclose(fp);
puts("\n");
}
}