Results 1 to 3 of 3
I have three question:
1. How to replace quotation mark when I want to use for file path, for example in fout("/home/somebody/ file .txt") I wanted to change the file ...
- 08-03-2007 #1
C++ questions
I have three question:
1. How to replace quotation mark when I want to use for file path, for example in fout("/home/somebody/file.txt") I wanted to change the file path using the other file name typed in by the user ? I dont want to use path explicitly, but instead dinamically changing paths.
2. How to declare a string constant:
I use
const char home[15]="/home/minthaka/";
but there's an error.
3. Do I have to use strcat(s1,s2) to concatenate strings or could I have
s3= s2+s3;If you need a CD/DVD catalogizer, give a try to my program:
http://www.kde-apps.org/content/show...content=100682
Linux Usert#430188
- 08-03-2007 #2Just Joined!
- Join Date
- Nov 2006
- Location
- Hyderabad
- Posts
- 85
- 08-04-2007 #3
1) If you're asking how to dynamically generate a string, sprintf() is indeed the way to go. It takes in a buffer, a pattern (the same style as printf()), and the values to fill into the pattern. It's basically like using printf() except that it stores the value into the provided buffer instead of printing it. See "man sprintf" for more details.
If that's not the question, please be clearer.
2) What error are you getting? That code compiles fine for me.
3) You have to use strcat(). The reason for this is simple. Let's assume we have the following code:
So here, s1 is a character pointer, and s2 is a character pointer. Because they are pointers, their only value is actually a single number that is the memory address that they reference. If you attempt to add them together (s1 + s2), you would actually be doing pointer arithmetic, which would figure out the memory location exactly (value of s2) 1-byte (or whatever the size of a char is) chunks down the line.Code:... char *s1 = "Hello "; char *s2 = "World"; ...
strcat(), on the other hand, looks at the actual values pointed to by the pointers, and works with those chars (and not the pointers to chars).
If you don't know about pointers yet, then don't worry: a pointer is basically a variable that references a value, rather than actually being that value itself. You will learn that arrays are basically pointers.
I hope that helps! Let us know if you have any questions.DISTRO=Arch
Registered Linux User #388732


Reply With Quote
