ie, char *buffer;
buffer contains "hello";
i would like to erase the letter 'o',
how would i do that?
thanks,
ie, char *buffer;
buffer contains "hello";
i would like to erase the letter 'o',
how would i do that?
thanks,
can't you do
? I have never tried this so...Code:strcat(buffer,"\b");
Last edited by ErionD; 04-06-2002 at 10:52 AM.
Why not just replace the last character with a " "?
"only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein
wow, it worked hehe, inserting a ' '; thanks guys!
well i guess strcat would work too,
this requires a null terminated string and will leave an extra null character at the end of the string. Since it is dynamic, you could create a new array first, do the change & copy, then delete the first arrayCode:int count; //finds end of string for(count = 0 ; buffer[counter] ; count++) ;//required count--;//set count to last character buffer[count] = '\0'; //overwrite last character
Last edited by Syneris; 04-08-2002 at 02:08 PM.
this is a bit faster:
buffer[strlen(buffer) - 1] = ' ';
not sure if you need the "- 1" part because i dont know if strlen counts the at the end of the string as part of the string. also, i dunno if strlen works around zero or one, so try both.
hope i didnt just confuse you .
lol! i have no idea why i said to use a loop instead of strlen...
you should subtract 1 from strlen
I don't think you need the -1 when using strlen because it doesn't count the null character . strlen("hello") should return 5 instead of 6.
you do because arrays start with 0 instead of 1
just dont wright the "o"
buffer[strlen(buffer) - 1] = ' ';
what happens when strlen(buffer)==0?
spell check wriiting i keep forgeting
compiler won't give an error, but you will still be writing to memory. This almost always cause an error when the program is run.Originally posted by rip1968
buffer[strlen(buffer) - 1] = ' ';
what happens when strlen(buffer)==0?
len=strlen(buffer);
if(len!=0)
buffer[len-1]='\0';
you're right, you do have to subtract 1 to get to the right index, I was just thinking about returning the size of buffer.