这是我的代码:
#include<stdio.h>
int main()
{
int a = '\0';
while ((a = getchar()) != EOF){
if (a != ' ' || a != '\t' || a != '\n' || a != ';' || a != ',' || a != '.'){
putchar(a);
}
else{
continue;
}
}
system("pause");
return 0;
}
我需要从输入文件中读取一首诗,并输出不带空格或标点符号的诗。必须使用 I/O 变化来完成。我到处搜索过,但似乎找不到如何按照我需要的方式做到这一点。非常感谢任何帮助...
最佳答案
希望这能解决您的问题。对字符使用 ascii 值。还可以使用 fgetc/fputc/fscanf/fprintf 等进行文件 i/o 相关操作。 ASCII 图表链接在这里 ASCII Chart VALUES .
#include<stdio.h>
int main()
{
FILE *pfile=NULL;
char data[255];
int i=0;
pfile=fopen("poem.txt","r");
while((data[i]=fgetc(pfile)) != EOF)
{
if(data[i]> 32 && data[i] < 123)
{
if(data[i] != 44 && data[i]!= 45 && data[i]!=46 && data[i]!=33)
{
//In the above 'if statement' you can add more characters/special
//characters you wish to exclude/ignore
printf("%c",data[i]);
i++;
}
}
}
return 0;
}
关于c++ - 在 C 中使用 exe 进行 I/O 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32855664/