2016-03-27 63 views
0

我想要求用戶鍵入他們想要我讀取的輸入文件,並且我想將一個輸入保存到兩個變量中,其中輸入文件將是「file.txt 「,但我希望輸出文件爲」file.txt.cvt「用新的文件擴展名寫文本文件

目前我遇到了問題。

這裏是我有什麼

printf("Enter file name: "); //asks for filename from user 
    scanf("%s %s.cvt", input_file, output_file);  //stores string as "filename" 

    inputf = fopen(input_file, "r"); /*file open stored string as 
            read only. 'filename, "r"'*/ 

    outputf = fopen(output_file, "w"); 
+1

只要有用戶輸入源文件規範,然後使用的strcpy和strcat的,其額外的擴展位彙編輸出文件規範。 –

回答

1
strcpy(output_file, input_file); // Make a copy of the input file name 
strcat(output_file, ".cvt"); // Add the ".cvt" suffix to it