hello,
In a string, the is white spaces.
In print output, I want to print without whitespaces(print only characters).
how can i do it.
hello,
In a string, the is white spaces.
In print output, I want to print without whitespaces(print only characters).
how can i do it.
There are a few ways. One would be to print the data one character at a time, checking to see whether it is a space using the isspace() function. You may have to include the ctype.h header file to use that function.
it's ironic considerate rarity patron of love higher knowledge engulfs me...
Sir,Thanks for your reply.
I am already know about isspace() fn.
But, after check condition if(isspace(char str)),
how can I print the characters with out space.ie., how to avoid the white space.
That's easy, just use the not operator.
Code:if( !isspace( str ) ) { printf("%c", str ); }
it's ironic considerate rarity patron of love higher knowledge engulfs me...
You know you can reply rather than just start a new thread every time you mean to reply...
Quzah.
Last edited by quzah; 06-14-2006 at 04:21 AM.
Hope is the first step on the road to disappointment.
Wow, that's some good caps aversion while still getting across the same feeling of caps. :P
it's ironic considerate rarity patron of love higher knowledge engulfs me...
U can even use something like :
Code:i=0; while(string[i]!='\0') { if(string[i] == ' ') i++; printf("%c",string[i]); i++; }
That will only skip white space character at a time. Also, if the last character in the string is a space, you'll skip to the null, then print the null, then advance past the end of the string, and then ... keep on chugging through your memory, in spaces you shouldn't be playing in.
Quzah.
Hope is the first step on the road to disappointment.
yeah, U were right about the last character being null.It did not strike me. He wants to skip all the white characters right? so, other than the case where the last char is a space ,this shud work..or will it?
No, your code won't work. What if there are two spaces in a row?
The issapce() should be in a while loop.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.