我可以将stdin分配给文件指针吗 [英] may i assign the stdin to the file pointer

查看:96
本文介绍了我可以将stdin分配给文件指针吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

printf(输入数据\ n");
fgets(buffer,250,stdin);

我使用上面的函数来从用户那里获取一个值并将其存储在变量varriable(它是一个字符数组)中.

我想知道如何将stdin文件指针分配给其他文件指针

以及如何从该文件指针读取数据..

请..

我只想使用该功能..

解决方案

您无法写入stdin:它是只读流.这相当于写鼠标并期望用户阅读消息...
您可以使用fprintf写入stdout:

fprintf(stdout, "Enter the data\n");
fgets(buffer,250,stdin);

但是无论如何,printf都是等效的-许多实现确实做到这一点:以stdout作为流参数从printf调用fprintf.


(至少)这是您第三次提出了这个问题,答案仍然相同:
1.您不能写入stdin.
2.您不能从stdout阅读.

我得到一个明显的印象,即您的问题并不能真正解释您要做什么,因此也许更多有关您要解决的问题的详细信息将为您提供更好的答案.


printf("Enter the data\n");
fgets(buffer,250,stdin);

i use the function above like that to get a value form the user and store in the buffer varriable(its a character array).

i want to know how to assign the stdin file pointer to the other file pointer

and how to read the data from that file pointer..

please..

i want to use that function only..

解决方案

You can''t write to stdin: it is a read-only stream. It would be the equivalent of writing to your mouse and expecting the user to read the message...
You could use fprintf to write to stdout:

fprintf(stdout, "Enter the data\n");
fgets(buffer,250,stdin);

But printf is the equivalent of that anyway - many implementations do exactly that: call fprintf from printf with stdout as the stream parameter.


This is (at least) the third time you have asked this question, and the answer remains the same:
1. You cannot write to stdin.
2. You cannot read from stdout.

I get the distinct impression that your question does not really explain what you are trying to do, so maybe a bit more detail on what problem you are trying to solve would get you a better answer.


这篇关于我可以将stdin分配给文件指针吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆