isspace?


 
Thread Tools Search this Thread
Top Forums Programming isspace?
# 1  
Old 11-03-2003
isspace?

Hello,

Does somebody know what is happening here? This piece of code should skip leading spaces (and others).

If isspace encounters a non space character, it doesn't return false.

If we analyze the " isspace(*cs_str);" in the debugger, it returns 0. If we check the value in b_space after assigning the value, the value is <> 0. We are using an UTF-8 encoded string. Could that have anything to do with it? It confuses the hell out of us.


const char* glb_strnskip_leading(const char* cs_str, size_t ul_size)
{
size_t ul_idx = 0;
int b_space = 0;

while((ul_idx < ul_size))
{
b_space = isspace(*cs_str);
if ( ! b_space )
{
break;
}
else
{
++cs_str;
++ul_idx;
}
}

...


I hope anyone has a clue what is happening here Smilie

Miriam
# 2  
Old 11-03-2003
Do you have to store the value in the variable to use it later on?

Or could you just replace
Code:
b_space = isspace(*cs_str);
if ( ! b_space )

with
Code:
if (!isspace(*cs_str))

I'm assuming that works; I haven't done much C programming.
# 3  
Old 11-03-2003
We had it like that, but then we saw that the code was doing strange things. (It was not leaving the if loop the first time, so that we would lose our first character).
To see what the isspace returned, we put the value in a variable.
# 4  
Old 11-03-2003
Well the code looks ok to me. I downloaded it and wrote a little wrapper. It works with both c and c++.

The only way that I can see this happening is a 64 bit/32 bit mismatch. Under that scenario, isspace would be returning a 32 bit integer. But b_space would want a 64 bit integer. So it grabs the correct 2 bytes (which are zero) and it grabs two more bytes which are not zero.
# 5  
Old 11-04-2003
what if...

you used something like:

while ( (ul_idx < ul_size) && (isspace(*cs_str)) ){
cs_str++;
ul_idx++;
}

you wouldn't loose the first character and you would not have to worry about casting and 32 vs 64 bit.

Rogier
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Isspace

Hey gurus.. I am still struggling with unix.. whats is the equivalent of isspace function in Unix shell scripting. I came across situation where a variable is a fixed lenth. And if it contains only spaces, then i should flag it as error. for eg.. vartemp=" " if isspace(vartemp)... (7 Replies)
Discussion started by: vipas
7 Replies
Login or Register to Ask a Question