日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言去空格换行符,关于文件操作,碰到空格就换行

發(fā)布時間:2025/3/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言去空格换行符,关于文件操作,碰到空格就换行 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓

#include

#include

#include

int main()

{

int i, off_set = 0;

char file_to_open[81];

char lines[1024], new_string[102400];

FILE *fp_read, *fp_write;

memset(file_to_open, 0x00, sizeof(file_to_open));

printf("Please input the files' full path:\n");

gets(file_to_open);

fp_read = fopen(file_to_open, "r");

if(NULL == fp_read)

{

printf("You've input a wrong path!\nProgramme will exit...\n");

sleep(3);

exit(1);

}

memset(new_string, 0x00, sizeof(new_string));

while(!feof(fp_read))

{

static int space_count = 0;

memset(lines, 0x00, sizeof(lines));

if(!fgets(lines, 1024, fp_read))

break;

printf("Now !");

for(i = 0; i < strlen(lines); i++)

{

if(lines[i] == 0x20)

{

lines[i] = '\n';

space_count ++;

}

}

strncpy(new_string + off_set, lines, strlen(lines));

off_set += strlen(lines);

}

printf(new_string);

fp_write = fopen("new_txt.txt", "w");

if(NULL == fp_write)

{

printf("Failed to open the new file!\n");

exit(1);

}

fprintf(fp_write, "%s", new_string);

printf("新文件寫入成功!\n");

return 0;

}

linux gcc 編譯成功并已測試,沒暫時沒發(fā)現(xiàn)bug。有問題繼續(xù)問。

如果你是在windows下跑這個代碼遇到錯誤,可能是中間有個sleep函數(shù),去掉便可。

總結(jié)

以上是生活随笔為你收集整理的c语言去空格换行符,关于文件操作,碰到空格就换行的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。