
急求答案!!c语言重定向问题,帮帮我吧!
看书时遇到c语言重定向的问题。#include<stdio.h>intmain(void){intch;while((ch=getchar())!=EOF)putchar...
看书时遇到c语言重定向的问题。
#include <stdio.h>
int main(void)
{
int ch;
while ((ch = getchar()) != EOF)
putchar(ch);
return 0;
}
这个是程序,文件名是echo_eof 它要我在echo_eof.exe中输入echo_eof<words就可以把words里的文字显示。我试过了没用!后来又试了把words改成words.txt也没用,words里面的东西就是显示不出来。echo_>words也没用。请问我哪里错了?该怎样做才能重定向?谢谢了!!
(words我放在盒echo_eof.exe同一个目录下) 展开
#include <stdio.h>
int main(void)
{
int ch;
while ((ch = getchar()) != EOF)
putchar(ch);
return 0;
}
这个是程序,文件名是echo_eof 它要我在echo_eof.exe中输入echo_eof<words就可以把words里的文字显示。我试过了没用!后来又试了把words改成words.txt也没用,words里面的东西就是显示不出来。echo_>words也没用。请问我哪里错了?该怎样做才能重定向?谢谢了!!
(words我放在盒echo_eof.exe同一个目录下) 展开
2个回答
展开全部
重定向不是这样用的 重定向是命令终端的概念
是在command 或者cmd里输入echo_eof<words.txt 这个时候 getchar()会从words.txt里取出字符
而不是在echo_eof.exe里
是在command 或者cmd里输入echo_eof<words.txt 这个时候 getchar()会从words.txt里取出字符
而不是在echo_eof.exe里
展开全部
你的意思是不是想把stdin替换为words这个文件啊,如果是的话,请使用函数freopen
#include <stdio.h>
int main(void)
{
int ch;
FILE* stream = freopen( "words", "r", stdin );
while ((ch = getchar()) != EOF)
putchar(ch);
return 0;
}
你把文件words放在和生成的exe一个目录下,确定是你程序的工作路径下;就可以完成你说的从文件中输入字符,然后打印在屏幕上;
#include <stdio.h>
int main(void)
{
int ch;
FILE* stream = freopen( "words", "r", stdin );
while ((ch = getchar()) != EOF)
putchar(ch);
return 0;
}
你把文件words放在和生成的exe一个目录下,确定是你程序的工作路径下;就可以完成你说的从文件中输入字符,然后打印在屏幕上;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询