04-21-2006 05:10 AM
04-21-2006 05:52 AM
Marco,
This is some very basic C ! In C strings are made as an array of char. A string is by definition terminated with the '\0' character which has the value 0. Anything after the '\0' is not considered to be part of the string, even if that is in the allocated memory space for the array of char. The function strlen() simply counts the number of chars from position 0 until it finds the '\0' character. (In contradiction to Pascal where the length of the string is stored in the first byte of the array of characters and no 'end-of-string character' is used).
Soultion:
I suppose you receive/have an array of chars. If you know for sure how many characters are in that array you can make a loop like:
for (i=0;i<lenght; i++){ if (arr[i] == 0) arr[i]=32; }
to clear the '\0' characters.
But make sure not the string is still terminated with a '\0' or you might experience some very strange effects in your program !
04-21-2006 09:48 AM