Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C (http://www.programmingforums.org/forum60.html)
-   -   Change the name of output file (http://www.programmingforums.org/showthread.php?t=10540)

jazz Jun 27th, 2006 11:04 AM

Change the name of output file
 
Hi All,

I have a program which takes a file as input and generates a output file with name FILExxx. The name of output file is hardcoded, and the name is same, whatever inputfile may be.

What I want is, if the input file is test, the output file should be named test_new, If the input file is myprog, the output file should be named as myprog_new.


Quote:

the input file is in some other location i.e.,
./myprog /data/tool2006/Myfile
so, when i do strcpy and strcat and compile the program, the output is generated in the path - /data/tool2006/Myfile_new

I want it in the current directory.
it is taking the whole path for strcpy, instead of only file name. how do i cpy only the file name

Thanx
jazz

Prm753 Jun 27th, 2006 11:07 AM

Take the whole name of the input file, and append "_new" to the end of it. Use strcat().

Zap Jun 27th, 2006 11:09 AM

Use strcat.
char * strcat ( char * dest, const char * src );
It appends src string to dest string. The terminating null character in dest is overwritten by the first character of src. The resulting string includes a null-character at end.

Parameters.

dest
Pointer to a null-terminated string with enough space allocated to contain both src and dest.
src
Null-terminated string to append.
Return Value.
dest is returned.

Portability.
Defined in ANSI-C.


Example.


:

/* strcat example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[80];
  strcpy (str,"strings  ");
  strcat (str,"have been ");
  strcat (str,"concatenated.");
  puts (str);
  return 0;
}


Output:
strings have been concatenated

Infinite Recursion Jun 27th, 2006 1:57 PM

With a prefix of './' on the new filename, it will be placed in your current directory.

ex: ./myFile.txt

jazz Jun 28th, 2006 2:54 AM

Thankx everyone.


All times are GMT -5. The time now is 12:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC