level 8
梦想家275
楼主
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<malloc.h>
int dq (void);
int dq(void) {
char b[1];
FILE *fp;
fp = fopen("/mnt/sdcard/1c/math.txt", "w");
if (fp == NULL)
printf("打开文件失败");
char a;
int i = 0;
while (a != '#') {
i++;
a = getche();
fprintf(fp, "%c", a);
}
fclose(fp);
char *str = (char *)malloc(sizeof(char) * i);
*str = NULL;
fp = fopen("/mnt/sdcard/1c/math.txt", "r+");
if (fp == NULL)
printf("打开文件失败");
a = 'q';
for (int p = 0; p < i - 1; p++) {
b[0]=(char)fgetc(fp);
strcat(str, b);
}
printf("\n输入的是:%s", str);
fclose(fp);
return 0;
}
int main(void){
dq();
return 0;
}
2016年07月07日 14点07分
1
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<malloc.h>
int dq (void);
int dq(void) {
char b[1];
FILE *fp;
fp = fopen("/mnt/sdcard/1c/math.txt", "w");
if (fp == NULL)
printf("打开文件失败");
char a;
int i = 0;
while (a != '#') {
i++;
a = getche();
fprintf(fp, "%c", a);
}
fclose(fp);
char *str = (char *)malloc(sizeof(char) * i);
*str = NULL;
fp = fopen("/mnt/sdcard/1c/math.txt", "r+");
if (fp == NULL)
printf("打开文件失败");
a = 'q';
for (int p = 0; p < i - 1; p++) {
b[0]=(char)fgetc(fp);
strcat(str, b);
}
printf("\n输入的是:%s", str);
fclose(fp);
return 0;
}
int main(void){
dq();
return 0;
}