LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2012, 07:47 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
How do I rename a file in C?


Hi:

The problem is to conserve the base and change the extension.
In fact I can do this if only I had a list of the string manipulation functions. Then I'd worry about the files themselves. You can assume there is one and only one dot in the original filename (not a homework). Ideas:
Code:
name is a variable and extension a constant here.

[1. duplicate the pointer ]
p = name

[2. q points to '.' ]
q = find('.', p) + 1   

[3. allocate mem to base and copy string beginning a p, in length
q - p, to base]
base = copy(p, q - p)   

[4. concatenate base and extension]
p = append(base, extension);

Last edited by stf92; 07-21-2012 at 09:11 PM.
 
Old 07-21-2012, 09:56 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by stf92 View Post
In fact I can do this if only I had a list of the string manipulation functions.
See string.h. Or write your own, there's nothing magic about string manipulation functions.
 
Old 07-21-2012, 10:58 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks. I did 'apropos string' and saw the string funtcions group togegher.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
String manipulation C++ miamagoo Programming 6 07-31-2010 12:55 PM
[SOLVED] string manipulation in a script file mahmoodn Linux - General 12 06-02-2010 01:39 PM
string manipulation jtag Linux - General 9 02-01-2010 08:07 AM
String manipulation in C xeon123 Programming 2 10-17-2007 01:17 PM
string manipulation mannahazarika Programming 6 12-31-2005 11:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration