hi, i have the following code... im just wondering if what i did was a good way to get the outcome.
Code:/* lets assume userinput = "hello" */ char address[1000] = {0, '/'}; strcat(address, userinput); /* address is now /hello */
This is a discussion on strings question within the C Programming forums, part of the General Programming Boards category; hi, i have the following code... im just wondering if what i did was a good way to get the ...
hi, i have the following code... im just wondering if what i did was a good way to get the outcome.
Code:/* lets assume userinput = "hello" */ char address[1000] = {0, '/'}; strcat(address, userinput); /* address is now /hello */
address will be "Hello", since the '/' is after a 0, so the address variable is essentialy the same as "" (empty string).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
icic so when it detects the 0, it interprets it as end of string.
Correct. To initialize the address array, you can code
They are all the same. The backslash is called an escape character.Code:char address[1000] = {'\0'}; or char address[1000] = '\0' ; or char address[1000] = 0 ;
Mac and Windows cross platform programmer. Ruby lover.
Quote of the Day
12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.
Amen brother!
thanks