I want to create a text file with the name entered by the user and with id concatinated,The file is getting created but the 1 is getting added at the last of extension every time i run it
#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;
}
the output i am getting is
Enter your name:
file
file1
.txt1 // i don't know why this 1 is getting added
Filename :file1.txt1
expected output is
Enter your name:
file
file1
.txt
Filename :file1.txt