strings with '00s' in!!
hi. I'm trying to adapt a program which uses strings of information to program into an external eeprom. Unfortunately, the new information I need to use contains zeros. Since strings null -terminate (I know that much) I'm losing the rest of my string after the first zero.
Is there a way I can re-define my string not to null - terminate? Or is there any other way I can include zeros in my string? Will I have to define a new array type altogether, or what??
Could you schow one of this strings please ...
Well, to begin with, a null terminator isn't just a 0... It's a \0.
If your strings are being chopped off, it's not because there's a 0 in them.
A string like:
char *eeprom_data = "8000";
will work fine, as character zero is different from the string terminator.
ok so its not just that its a zero, but rather because I have to define it as hex in my string, as in '\x00'?? although that still isn't \0 - is it??
Strings in C are character arrays that are terminated by a binary zero. If you have binary zeros, you don't have strings and cannot use the C string functions from string.h. What you have are byte arrays. Same datatype, but the string functions will not work correctly because of the zeros. Which functions from string.h do you want to use ? There are functions like memcpy, memcmp that do the same as the string functions just with raw data.
yeh thanks - thought as much. At the moment I'm cheating by flood-filling my memory with 00s before I start and creating a new string every time a 00 occurs, but it makes for messy code. I'm amending a program which is totally built around strings so there's a whole wad of stuff to be modified if I change the data type. Think I have a considereable amount of work to do - unless anyone can think of a better way around it??