Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 27th, 2006, 11:04 AM   #1
jazz
Newbie
 
Join Date: May 2006
Posts: 18
Rep Power: 0 jazz is on a distinguished road
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
jazz is offline   Reply With Quote
Old Jun 27th, 2006, 11:07 AM   #2
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 3 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Take the whole name of the input file, and append "_new" to the end of it. Use strcat().
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Jun 27th, 2006, 11:09 AM   #3
Zap
Guest
 
Posts: n/a
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
  Reply With Quote
Old Jun 27th, 2006, 1:57 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
With a prefix of './' on the new filename, it will be placed in your current directory.

ex: ./myFile.txt
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jun 28th, 2006, 2:54 AM   #5
jazz
Newbie
 
Join Date: May 2006
Posts: 18
Rep Power: 0 jazz is on a distinguished road
Thankx everyone.
jazz is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:22 PM.

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