New to C: I have a string that is 35 characters long excluding the ():
(New City )
I would like to create a new string that looks like this:
(New+City+++++++++++++++++++++++++++)
How can I go about this?
Well, since you declare replaceChar as a string you cannot do:
buffer = replaceChar;
This would mean that you want to assign a pointer address to a character...I think what you want to do is this:
int i;
char buffer[] = "abc def";
char replaceChar = '+';
for (i = 0; i < strlen(buffer); i++) {
if(buffer == ' ') {
buffer = replaceChar;
}
}
Note the difference between writing "+" and '+'. The first means "the address of a string containing a plus and then a null-character" and the second means "a plus-character". There is a seemingly subtle, but crucial difference.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.