0

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..

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ambarisha.kn
0

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");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.