From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
|
printf
和 scanf
函数实现输入输出)到一个文件,你需要改变stdin
和 stdout
文件指针。下面两个例子显示具体实现方法:#include <ansi_c.h>
int main (int argc, char *argv[])
{
FILE *copy;
printf ("This is printed to screen!\n");
copy = stdout;
stdout = fopen ("stdio test.txt", "w");
printf ("This is printed to a file!\n");
fclose (stdout);
stdout = copy;
printf ("Where is this line?\n");
return 0;
}
#include <ansi_c.h>
int main (int argc, char *argv[])
{
FILE *copy;
int x;
char y[100] = "\0";
printf ("This is printed to screen!\n");
scanf ("%d", &x);
copy = stdin;
stdin = fopen ("stdio test.txt", "r");
scanf ("%s", y);
fclose (stdin);
stdin = copy;
printf ("%s\n", y);
scanf ("%s", y);
printf ("%s\n", y);
return 0;
}
|