如何将一小段文字写入.txt文件?我已经使用Google搜索了3-4多个小时,但无法找到具体方法。
.txt
fwrite(); 有很多论据,我不知道该如何使用。
fwrite();
当您只想在文件中写一个名字和几个数字时,最容易使用的功能是什么.txt?
编辑:添加了一段我的代码。
char name; int number; FILE *f; f = fopen("contacts.pcl", "a"); printf("\nNew contact name: "); scanf("%s", &name); printf("New contact number: "); scanf("%i", &number); fprintf(f, "%c\n[ %d ]\n\n", name, number); fclose(f);
FILE *f = fopen("file.txt", "w"); if (f == NULL) { printf("Error opening file!\n"); exit(1); } /* print some text */ const char *text = "Write this to the file"; fprintf(f, "Some text: %s\n", text); /* print integers and floats */ int i = 1; float py = 3.1415927; fprintf(f, "Integer: %d, float: %f\n", i, py); /* printing single chatacters */ char c = 'A'; fprintf(f, "A character: %c\n", c); fclose(f);