| | |
whitespace
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
No, there's not a function in either the C or C++ library that will do that. You do it manually. First by finding the end of the string and walking back as long as the current character is whitespace, then replace the last occurance of whitespace with '\0'. Then by finding the first non-whitespace character in the string and shifting everything in the string back. You can do the latter with memmove.
I'm here to prove you wrong.
•
•
Join Date: Jul 2005
Posts: 91
Reputation:
Solved Threads: 0
Thanks Narue does it have to be replaced with '\0' or is it just a '0'? and would I have to replace all of the whitespace or just the last one for example:
"k,i,m, 0, , , ,0"
Also would it be easier for me beginner to programming not to use memmove as I have no idea how that function works I had a look on google but I didn't understand the examples I found?
"k,i,m, 0, , , ,0"
Also would it be easier for me beginner to programming not to use memmove as I have no idea how that function works I had a look on google but I didn't understand the examples I found?
>does it have to be replaced with '\0' or is it just a '0'?
'\0' is an escape character with the value of 0 that's used as a string terminator. '0' is not the same thing.
>and would I have to replace all of the whitespace or just the last one
Just the last one. If the string has {'t','e','s','t',' ',' ',' ','\0'} then you only need to replace the first space character after 't' with '\0'. That truncates the string appropriately.
>Also would it be easier for me beginner to programming not to use memmove
The manual solution isn't any simpler:
Compare that to memmove:
'\0' is an escape character with the value of 0 that's used as a string terminator. '0' is not the same thing.
>and would I have to replace all of the whitespace or just the last one
Just the last one. If the string has {'t','e','s','t',' ',' ',' ','\0'} then you only need to replace the first space character after 't' with '\0'. That truncates the string appropriately.
>Also would it be easier for me beginner to programming not to use memmove
The manual solution isn't any simpler:
C++ Syntax (Toggle Plain Text)
for ( i = 0; a[i] != '\0'; i++ ) { if ( !isspace ( a[i] ) ) break; } if ( i > 0 ) { for ( j = 0; a[i] != '\0'; i++, j++ ) a[j] = a[i]; a[j] = '\0'; }
C++ Syntax (Toggle Plain Text)
for ( i = 0; a[i] != '\0'; i++ ) { if ( !isspace ( a[i] ) ) break; } if ( i > 0 ) memmove ( a, a + i, strlen ( a + i ) + 1 );
I'm here to prove you wrong.
![]() |
Similar Threads
- Site review? (Website Reviews)
- Utilizing Whitespace Effectively (Site Layout and Usability)
- Eliminating Whitespace characters while parsing XML Files using DOM (Java)
- Whitespace (Site Layout and Usability)
- How to modify/change a logo on a wallpaper? (Graphics and Multimedia)
Other Threads in the C++ Forum
- Previous Thread: Displaying hyphens and backslashes in console window
- Next Thread: Increasing DOS console window
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






