简体   繁体   English

使用exe在C中进行I / O重定向

[英]I/O redirection in C using exe

Here is my code: 这是我的代码:

#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 need to read a poem from an input file, and output the poem with no spaces or punctuation. 我需要从输入文件中读取一首诗,并输出没有空格或标点符号的诗。 Must be done using I/O variation. 必须使用I / O变化来完成。 I've searched all over, but I can't seem to find how to do this the way I need. 我已经搜索了所有内容,但似乎找不到找到所需方式的方法。 Any help is much appreciated... 任何帮助深表感谢...

Hope this solves your Problem. 希望这能解决您的问题。 Use ascii values for character. 使用ascii值表示字符。 Also use fgetc/fputc/fscanf/fprintf etc for file i/o related operations. 还将fgetc / fputc / fscanf / fprintf等用于文件I / O相关操作。 ASCII CHART link here ASCII Chart VALUES . ASCII CHART链接在此处ASCII图表值

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM