|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
int main()
{
FILE *fp;
int a;
char b[20];
fp=fopen("shiyan.txt","a+");
for(a=0;a<5;a++){
fseek(fp,0L,SEEK_SET);
scanf("%s",b);
fprintf(fp,"%s ",b);
}
fclose(fp);
}
这是我的代码
原意是想把每次b的值输入到文件最前的
就是输入a b c d e
到文件里是 e d c b a
但是失败了
我是为了将一个不知道多长的链表倒序写到文件里的,如果有其他的办法 ,也请告诉我把。谢谢谢谢谢谢!!
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- char str[100];
- char buf[100];
- int buf_len = 0;
- int ch;
- FILE *file;
-
- file = fopen("data.txt", "r+");
- if(file)
- {
- while((ch = fgetc(file)) != EOF)
- buf[buf_len++] = ch;
- fclose(file);
- }
- printf("请输入: ");
- fgets(str, 100, stdin);
- int str_len = strlen(str) - 2; // 不要 '\n'
- file = fopen("data.txt", "w");
- while(str_len >= 0)
- fputc(str[str_len--], file);
- for(int i = 0; i < buf_len; ++i)
- fputc(buf[i], file);
- fclose(file);
- return 0;
- }
复制代码
|
|