hi,
I was wondering how I could look through a char array and remove any white space characters I found. eg if I a had a char array of
char buffer[] = "hell o";
I could modify it to "hello";
can anyone help
Thank you
Craig Smith
Printable View
hi,
I was wondering how I could look through a char array and remove any white space characters I found. eg if I a had a char array of
char buffer[] = "hell o";
I could modify it to "hello";
can anyone help
Thank you
Craig Smith
-PreludeCode:char a[] = "Hell o",
b[10] = {0};
for ( int x = 0, y = 0; a[x] != '\0'; x++ )
if ( !isspace ( a[x] ) b[y++] = a[x];
Didn't you ask this already?
Well to do it in a more practical sense, why not just monitor what is put in the array (whether it is through user input or whatever):
Another way is to use the isspace() function in ctype.h with an if-else tree.Code:while( (c = cin.get()) != '\n')
{
switch( c )
{
case ' ': // If it is a space
break;
default:
array[i++] = c;
break;
}
}
If you want to just go through an array and delete spaces, it is just searching and shifting. I think you should be able to figure out the code for it. Here' s the pseudo anyway:
for i = 0 to ArrayLength
if you find a space then shift everything after it up one
Good luck