I/O重定向在C使用exe

I/O redirection in C using exe

本文关键字:使用 exe 重定向      更新时间:2023-10-16

下面是我的代码:

#include<stdio.h>
int main()
{
    int a = '';
    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相关操作。

#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;
}