获取输入文件名并复制它,但使用不同的文件扩展名

Take an input file name and copy it but with a different file extension

我正在尝试编写一个 C 程序,它接受一个输入文件名,并输出一个同名但扩展名不同的文件。例如,它会接收文件 example.in 并输出 example.out。

我目前正在尝试:

char *fname = argv[2];
char *fout = fname;

但我不知道如何继续更改文件的扩展名。

查看 strrchr

来自手册页:

The strrchr() function returns a pointer to the last occurrence of the
character c in the string s.

这将使您能够识别“.”所在的位置。是。从那里,您可以将字符串的开头复制到新的内存区域,并且 strcat 结尾在