#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void convertToTxt(const char* filename) {
FILE* file = fopen(filename, "r");
if (file == NULL) {
printf("Failed to open file: %s\n", filename);
return;
}
char outputFilename[256];
strcpy(outputFilename, filename);
// 替换文件扩展名
char* dot = strrchr(outputFilename, '.');
if (dot != NULL) {
*dot = '\0';
}
strcat(outputFilename, ".txt");
FILE* outputFile = fopen(outputFilename, "w");
if (outputFile == NULL) {
printf("Failed to create output file: %s\n", outputFilename);
fclose(file);
return;
}
char ch;
while ((ch = fgetc(file)) != EOF) {
fputc(ch, outputFile);
}
fclose(file);
fclose(outputFile);
printf("File converted successfully: %s\n", outputFilename);
}
int main() {
convertToTxt("example.h");
convertToTxt("example.hxx");
return 0;
}
文件后缀名转换
最新推荐文章于 2024-06-17 08:19:26 发布