我想创建一个文本文件,其名称由用户输入并连接 id,该文件正在创建,但每次运行时都会在扩展名的最后添加 1
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
int main(int argc, char const *argv[])
{
char name[50];int id=1;
printf("Enter your name:\n");
scanf("%s",name);
char ids[10];
itoa(id, ids, 10);
strcat(name,ids);
printf("%s\n",name );
char ex[4]=".txt";
printf("%s\n",ex );
strcat(name,ex);
printf("Filename :%s\n",name);
return 0;
}
我得到的输出是
Enter your name:
file
file1
.txt1 // i don't know why this 1 is getting added
Filename :file1.txt1
预期输出是
Enter your name:
file
file1
.txt
Filename :file1.txt