I have input files like this
a.iup
b.iup
c.iup.......

i have these input files in a variable called fname;
like this

char *fname="c:\\iupfiles\\a.iup";
every time i will get file name in this variable. But how to concatenate the variable with some other name like as follows in output file name.

in a loop i will get one file at one time. I have write the output into file for each input file as
a_res.txt
b_res.txt
c_res.txt...

like this. How to do this..

Recommended Answers

All 2 Replies

you can use either sprintf() or strcat() to format the output file name. Example:

char outname[255];
char inputname[255];
char* ptr;

printf("Enter a file name\n");
fgets(inputname,sizeof(inputname),stdin);
strcpy(outname, inputname);
// truncate the extension
ptr = strchr(outname,'.');
if(ptr != NULL)
   *ptr = '\0';
// now add new filename
strcat(outname,"_res.txt");

Thnaks. Its working fine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.