C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 9th, 2003, 07:20 PM
kubicon's Avatar
kubicon kubicon is offline
pogremar
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: At Work
Posts: 950 kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 57 m 55 sec
Reputation Power: 7
replacing things on a string

I have a char array like so:
char path[275]={0};
in the array, I have this string:
c:\test\other
I want to change that string to:
c:\\test\\other

Reply With Quote
  #2  
Old July 9th, 2003, 09:23 PM
#define Gangsta's Avatar
#define Gangsta #define Gangsta is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Representin' Quebec
Posts: 106 #define Gangsta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
... I don't get what you are trying to say! You put: "char path[275]={0}; " First of all (unless 0 means something else) '\0' is the null character. And why initialize it? And if you want to enter your own filename at runtime do like this:

char path[275];
cin.getline(path, 274, '\n');
// 274 to leave space for the null character at the end...

Do you understand this?

Reply With Quote
  #3  
Old July 9th, 2003, 11:24 PM
kubicon's Avatar
kubicon kubicon is offline
pogremar
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: At Work
Posts: 950 kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 57 m 55 sec
Reputation Power: 7
Sorry about that. I'm not been very descriptive

the first thing I'm doing is initializing the array so that it doesn't contain garbage. I like initializing my arrays.

The string that it contains comes from a text file. I want to use that string as a file name for functions such as FindFirstFile(); however, as we know, if you pass functions an string like this:
c:\test\other
it will be no good as we have to scape our backlash. So, I already have the string, what i need is a function/method to turn the string c:\test\other that is contained in path[] to c:\\test\\other so that I could use it the above named functions.

Reply With Quote
  #4  
Old July 10th, 2003, 10:50 AM
#define Gangsta's Avatar
#define Gangsta #define Gangsta is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Representin' Quebec
Posts: 106 #define Gangsta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Can't you just open your textfile and change it?

But I have an alternative... Make a header file! (Do you know how?)

Last edited by #define Gangsta : July 10th, 2003 at 11:00 AM.

Reply With Quote
  #5  
Old July 10th, 2003, 01:13 PM
kubicon's Avatar
kubicon kubicon is offline
pogremar
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: At Work
Posts: 950 kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 57 m 55 sec
Reputation Power: 7
That's all basic stuff... How would a header file help, though?
I need to do what I'm asking from within the app. The text file is a configuration file for a program that I'm making.

Reply With Quote
  #6  
Old July 10th, 2003, 01:25 PM
3dfxMM 3dfxMM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 267 3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 19 m 53 sec
Reputation Power: 13
If the '\' character is already in the character array you don't need to escape it. You only need to do that if you use it in a string literal.

Reply With Quote
  #7  
Old July 10th, 2003, 03:16 PM
kubicon's Avatar
kubicon kubicon is offline
pogremar
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: At Work
Posts: 950 kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 57 m 55 sec
Reputation Power: 7
Really? I'm gonna check it out.
If you're right, OMG!
I can't believe I didn't try that.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > replacing things on a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT