|
もう少しエレガントなやり方はあると思うけど。。。
#include <stdio.h>
#include <string.h>
#define MAX_NAME 32
int main(void)
{
char filename[MAX_NAME];
char cpfile[MAX_NAME];
char ex[MAX_NAME];
char *p_c;
printf("input name ==>");
scanf("%s", filename);
strcpy(cpfile, filename);
p_c = strrchr(cpfile, '.');
if (p_c != NULL) {
strcpy(ex, (p_c + 1));
*p_c = '\0';
}
if (0 == strcmp(ex, "txt"))
strcat(cpfile, ".doc");
else if (0 == strcmp(ex, "doc"))
strcat(cpfile, ".txt");
else
strcat(cpfile, ".err");
printf("%s\n%s\n", filename, cpfile);
return 0;
}
|