啊哈磊_编程从这里起步

标题: 哈哈又是文件操作的问题...... [打印本页]

作者: 吴明程    时间: 2017-12-2 15:37
标题: 哈哈又是文件操作的问题......
上次我问了一下读取文件中的数字的问题......圆满地解决了这个问题(哦耶)
这次吗.......就是写数的问题了......
如图:

测验一下清除后在写会变成什么样......
改好后的文件如下:

请问该怎么去除前面那些空格呢......
题外话:
我清除了文件里的内容,怎么还会留个“尸体”(空格)在那里呢(ˉ▽ˉ;)



作者: 创世菌    时间: 2017-12-2 16:27
本帖最后由 创世菌 于 2017-12-2 16:35 编辑

我从不用那么复杂的方法去做文件操作![mw_shl_code=c,true]#include <stdio.h>
int main()
{
    FILE *fp=fopen("1.txt","w");
    fprintf(fp,"你好,欢迎你来到C++的世界");
    fclose(fp);
    fp=fopen("1.txt","w");
    fprintf(fp,"hello");
    fclose(fp);
    return 0;
}
[/mw_shl_code]

作者: 吴明程    时间: 2017-12-2 17:34
创世菌 发表于 2017-12-2 16:27
我从不用那么复杂的方法去做文件操作![mw_shl_code=c,true]#include
int main()
{

谢谢创世菌!!!
现在已经解决了!!!
成功图:


作者: 创世菌    时间: 2017-12-2 22:11
[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *path=(char *)calloc(256,sizeof(char));
    gets(path);
    FILE *fp=fopen(path,"w");
    fprintf(fp,"你好,欢迎你来到C++的世界");
    fclose(fp);
    fp=fopen(path,"w");
    fprintf(fp,"hello");
    fclose(fp);
    return 0;
}
[/mw_shl_code]
作者: 创世菌    时间: 2017-12-3 15:19
本帖最后由 创世菌 于 2017-12-3 15:36 编辑

[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *path=(char *)calloc(256,sizeof(char));
    gets(path);
    FILE *fp=fopen(path,"w");
    fgets(path,256,fp);
    puts(path);
    fclose(fp);
    return 0;
}[/mw_shl_code]
作者: 吴明程    时间: 2017-12-4 20:07
不对啊......至少我这边是不对的......
______________________________________________________

作者: 创世菌    时间: 2017-12-6 21:17
将[mw_shl_code=c,true]fopen(path,"w");[/mw_shl_code]改为[mw_shl_code=c,true]fopen(path,"r");[/mw_shl_code]




欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2