-5
我有一些問題,我想讀取輸入的.txt文件參數並寫出output.txt。我只能找到一行,我怎麼能找到這個問題的所有行相同?而當input.txt文件參數刪除時,會刪除output.file中的字符。讀取文件並寫入文件C
input.txt的文件的詳細信息
write: 3 a 4 b 1 \n 2 d
delete: 1 a 2 b
output.txt的適用第一paramater將導致
aaa bbbb
dd
output.txt的適用第二paramater將導致
aa bb
dd
感謝爲你的回答提前
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main(void)
{
FILE *read, *write; /* files pointers */
char *source_file = "input.txt";
char *dest_file= "output.txt";
int count;
char ch;
char choose []="write";
int z=0;
if((read=fopen(source_file, "r")) == NULL) /* files check ? */
{
printf("%s didnt' open .\n", source_file);
exit(1);
}
if((write=fopen(dest_file, "w")) == NULL)
{
printf("%s didnt. open \n", source_file);
exit(2);
}
fscanf(read,"%s%d%c",&choose,&count,&ch);
while((ch = fgetc(read)) != EOF)
{
printf("%d%c",count,ch);
z=0;
for (; z<count; z++)
{
fprintf(write,"%c",ch);
printf("\n");
}
fprintf(write," ");
fscanf(read,"%d%c",&count,&ch);
printf("\n");
}
fclose(read); /* files close */
fclose(write);
printf("%s > %s\n",source_file, dest_file);
return 0;
}
0)'1 \ N' - >'2 \ N' 1)'字符選擇[] = 「寫」;'爲小'delete'。 2)'%s%d%c「' - >''%[^:]:%d%c」'但是不能讀取'\ n'(兩個字符) – BLUEPIXY
謝謝您的迴應,當我試過我看到了錯誤,我怎麼能解決這個問題? – youngman
這個建議,我認爲在你對delete命令應用delete命令後,對待任何好的(並且容易的),例如'write:3 a 4 b 1 \ n 2 d delete:1 a 2 b' ==>將寫入命令更新爲'write:2 a 2 b 1 \ n 2 d' – BLUEPIXY