我尝试创建一个.c程序,当它运行时,它接受一个文件,并且只打印上面有东西的行(空格、字母、number....etc),而不打印空行。
我需要在使用ubuntu的虚拟机上运行它(它运行的是最新版本的ubuntu)。到目前为止,我只打印了它的内容,而不是像在文件中那样打印在行上。
代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char *name = argv[1];
FILE *f = fopen(name, "r");
char x;
while(fscanf(f, "%c" , &x) > 0)
{
printf("%c", x);
if(x == '\n')
{
printf("\n");
}
}
}
文件内容:
as
d
3
结果:
asd3
期望的结果:
as
d
3
https://stackoverflow.com/questions/56419404
复制相似问题