编程题:将字符串写入文件noobdream.txt
#include <stdio.h> #include<stdlib.h> #include <stdbool.h> #include <string.h> int main() { FILE *fp=NULL; fp=fopen("大学课程/lx.txt","w+"); fputs("hello i am Grace",fp); fclose(fp); return 0; }
#include <stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #define N 100 int main(void) { FILE* fp; char string[N];
fp = fopen("D:\\OneDrive\\桌面\\noobdream.txt", "w"); if (fp == NULL) { puts("ERROR"); exit(1); } printf("输入字符串:\n"); fgets(string, N - 1, stdin); fprintf(fp, "%s", string); printf("字符串已成功写入文件noobdream.txt\n"); fclose(fp); return 0;
}
#include<stdio.h> #define N 1000 int main { char source[N]={0}; FILE *fp; fp = fopen ("noobdream.txt","wb"); if( fp == NULL ){ printf("创建文失败"); return -1; } gets(source); fprintf(fp,"%s",source); fclose(fp) return -1;
#include<stdio.h>
int main() { char source[1024]={0}; FILE * fp=fopen("noobdream.txt","w"); gets(source); fprintf(fp,"%s",source);
if(fp!=NULL) { fclose(fp);
fp=NULL; }
return 0; }
#include <stdio.h>
int main() { char str[20]; scanf("%s",str); FILE *fp; fp=fopen("D:\\noobdream.txt","w"); fputs(str,fp); fclose(fp); return 0; }
#include <stdi...
用户登录可进行刷题及查看答案
#include <stdio.h> #include <stdlib.h> /* exit() 函数 */ int main() { char sentence[1000]; FILE *fptr; fptr = fopen("noobdream.txt", "w"); if(fptr == NULL) { printf("Error!"); exit(1); } printf("输入字符串:\n"); fgets(sentence, (sizeof sentence / sizeof sentence[0]), stdin); fprintf(fptr,"%s", sentence); fclose(fptr); return 0; }
登录后提交答案