![]() |
| ||
| scanning char array for \0 problem I'm trying to make a function that can scan a char array, and finish it's business when it comes to a '\0'. so here is the for loop i came up with: for( i=0 ; charArray[i] != '\0' ; i++ )But here is an example of entered data: "1234 432" It seems to end the loop at the space. So are spaces and null characters similar? how can i differentiate between the two so that it keeps going right through a space and only stops at a null? |
| ||
| Re: scanning char array for \0 problem >So are spaces and null characters similar? No, not at all. >how can i differentiate between the two You don't need to differentiate between the two. You need to figure out why your code is stopping when you don't think it should. We can help, but you need to post more code. Preferably a complete program that exhibits the problem. |
| ||
| Re: scanning char array for \0 problem here ya go: #include <stdio.h> |
| ||
| Re: scanning char array for \0 problem Ah, the loop ends at the space because the string ends at the space. scanf stops reading input at spaces. So when you enter "1234 432" the userString gets "1234", and " 432" is left waiting to be read. If you want to get a string from the user try using fgets(). Good luck. |
| ||
| Re: scanning char array for \0 problem Quote:
|
| All times are GMT -4. The time now is 3:25 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC