c语言去空格换行符,关于文件操作,碰到空格就换行
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
#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 編譯成功并已測試,沒暫時沒發現bug。有問題繼續問。
如果你是在windows下跑這個代碼遇到錯誤,可能是中間有個sleep函數,去掉便可。
總結
以上是生活随笔為你收集整理的c语言去空格换行符,关于文件操作,碰到空格就换行的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: MySQL入门之数据完整性约束与表维护
- 下一篇: idea 父文件_万事开头难!最新MyB
