从C程序内部读取/写入其他文件 [英] Reading/Writing other files from inside a C program
问题描述
我正在学习C,所以我决定试用r / w-ing到其他文件。可以
任何人请告诉我为什么我在运行
计划时出现以下错误?
成绩单:
姓名?
Nikhil R. Mulani
巴士错误
代码:
#include< stdio.h>
main()
{
char name [60];
FILE * Fp;
Fp = fopen(" /deter.dat" ;," w");
printf("姓名?\ n");
scanf("%s",name);
fprintf(Fp," Name:%s \\ \\ n",name);
int fclose(FILE * Fp);
}
I am learning C, so I decided to try out r/w-ing to other files. Can
anyone please tell me why I get the following error when running the
program?
Transcript:
Name?
Nikhil R. Mulani
Bus error
Code:
#include <stdio.h>
main()
{
char name[60];
FILE *Fp;
Fp = fopen("/deeter.dat", "w");
printf("Name?\n");
scanf("%s",name);
fprintf(Fp, "Name: %s\n", name);
int fclose( FILE *Fp );
}
推荐答案
ex******@gmail.com 写道:
我正在学习C,所以我决定试用r / w-ing到其他文件。可以
任何人请告诉我为什么我在运行
程序时会出现以下错误?
[...]
scanf("%s",name);
[...]
I am learning C, so I decided to try out r/w-ing to other files. Can
anyone please tell me why I get the following error when running the
program?
[...]
scanf("%s",name);
[...]
你错过了一个&在名称之前。
-
如果盖革计数器没有点击,
咖啡,她就不是厚厚的
You miss an "&" before "name".
--
If geiger counter does not click,
the coffee, she is just not thick
谢谢!
thanks!
Sebastian Hungerecker写道:
Sebastian Hungerecker wrote:
ex******@gmail.com 写道:
我是学习C,所以我决定尝试r / w-ing到其他文件。可以
任何人请告诉我为什么我在运行
程序时会出现以下错误?
[...]
scanf("%s",name);
[...]
I am learning C, so I decided to try out r/w-ing to other files. Can
anyone please tell me why I get the following error when running the
program?
[...]
scanf("%s",name);
[...]
你错过了一个&在name之前。
You miss an "&" before "name".
我没看过原文,但如果name是char数组,
那么前置&是不正确的。 %s匹配char *,而不是char(*)[]。
另外,OP应该知道scanf(%s,name)打开程序
直到缓冲区溢出攻击的可能性。
I haven''t seen the original article, but if name is an array of char,
then prepending & is incorrect. %s matches char *, not char (*)[].
Also, the OP should be aware that scanf("%s", name) opens the program
up to the possibility of a buffer overrun attack.
这篇关于从C程序内部读取/写入其他文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!