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.
Printable View
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.
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 );
}
You know you can reply rather than just start a new thread every time you mean to reply...
Quzah.
Wow, that's some good caps aversion while still getting across the same feeling of caps. :P
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.
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.