<分区>
我想在 txt 上介绍信息,我有这个:
int main(){
FILE * file;
file=fopen("viajes.txt", "w");
char select;
char dni[tm_dni];
printf("Introduce DNI:\n");
scanf("%s", dni);
fputs("DNI cliente:", file);
}
<分区>
我想在 txt 上介绍信息,我有这个:
int main(){
FILE * file;
file=fopen("viajes.txt", "w");
char select;
char dni[tm_dni];
printf("Introduce DNI:\n");
scanf("%s", dni);
fputs("DNI cliente:", file);
}
最佳答案
这个:
fputs("DNI cliente:", file);
打印一个静态字符串到文件,然后你需要跟随动态数据:
fputs(dni, file);
您还可以:
fprintf(file, "DNI cliente: %s\n", dni);
当然,您还应该检查各种 I/O 调用(包括 scanf()
)是否成功。
关于c - 如何使用 fputs C 在 .txt 上插入变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49151807/