如何用c语言在文本文档中输入回车键
2011-07-04
展开全部
fgetc从文件读一个字符 ,回车符是'\n'
例如,从test.txt读一行
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE * fp;
char * name = "test.txt";
char c;
if( (fp=fopen(name,"rb")) == NULL )
{
printf("Can not open %s!\n",name);
exit(1);
}
c = fgetc(fp);
while( (!feof(fp)) && (c != '\n') )
{
printf("%c",c);
c = fgetc(fp);
}
fclose(fp);
return 0;
}
例如,从test.txt读一行
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE * fp;
char * name = "test.txt";
char c;
if( (fp=fopen(name,"rb")) == NULL )
{
printf("Can not open %s!\n",name);
exit(1);
}
c = fgetc(fp);
while( (!feof(fp)) && (c != '\n') )
{
printf("%c",c);
c = fgetc(fp);
}
fclose(fp);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询