如何通过 Eclipse 使用 C 写入 txt 文件(通过控制台输入)
How to write in txt file using C by Eclipse (typing by console)
我试图在一些网页上找到这个问题的答案,最后我在这里尝试并找到了一个类似的答案,但它完全不能满足我的问题
Here answers how to write some text by writing it in a constant, but it doesn't allows you to whrite by console
我是编程界的新手,如果我的问题太普通,我深表歉意。此外,我也为我的英语水平感到抱歉。
提前致谢。
#include "modificator.h"
int main(void) {
editFile();
return 0;
}
void editFile() {
FILE* f;
Cadena cad, res; //"Cadena is an array of char"
printf("Write the access rout to file required: \n");
scanf("%s", cad);
f = fopen(cad, "w");
if (f == NULL) {
printf("Wrong opening file\n");
}
const char *text = scanf("%s", res);
fprintf(f, "Some text: %s\n", text);
fclose(f);
}
const char *text = scanf("%s", res);
不不不。 scanf()
returns int
类型的值
int chk = scanf("%s", res); // beware buffer overflows
if (chk == 1) {
fprintf(f, "Some text: %s\n", res);
}
我试图在一些网页上找到这个问题的答案,最后我在这里尝试并找到了一个类似的答案,但它完全不能满足我的问题
Here answers how to write some text by writing it in a constant, but it doesn't allows you to whrite by console
我是编程界的新手,如果我的问题太普通,我深表歉意。此外,我也为我的英语水平感到抱歉。
提前致谢。
#include "modificator.h"
int main(void) {
editFile();
return 0;
}
void editFile() {
FILE* f;
Cadena cad, res; //"Cadena is an array of char"
printf("Write the access rout to file required: \n");
scanf("%s", cad);
f = fopen(cad, "w");
if (f == NULL) {
printf("Wrong opening file\n");
}
const char *text = scanf("%s", res);
fprintf(f, "Some text: %s\n", text);
fclose(f);
}
const char *text = scanf("%s", res);
不不不。 scanf()
returns int
类型的值
int chk = scanf("%s", res); // beware buffer overflows
if (chk == 1) {
fprintf(f, "Some text: %s\n", res);
}