|
This is because your expression newItemIDPointer + i is a pointer to the character at offset i in the string, not the value (character) at that location. You need to dereference the pointer to get the value, eg: *(newItemIDPointer + i)Or a more obvious way to do it is: newItemIDPointer[i]To explain: Let's say you have a pointer to a string, called p: char *p = "ABCDE";Let's say that the pointer p happens to have a value 0x4001. That would be the address of the first character in your string, which happens to be the letter ASCII value of A (I just totally made that number up, in practice the operating system and/or compiler determine the actual memory location)... So then, p + 1 will give us 0x4002.. the location of the letter B. It is NOT the ASCII value of B, which happens to be 66 in decimal... That is what you want to be passed to isspace.. the value stored in that memory location, not the address of the memory location. This is one of the toughest things for beginners to C, once you get a good visual in your head of when you are manipulating the address of a location in memory and when you are manipulating the data stored at that location, the rest of C is pretty easy... (责任编辑:) |
