strings with '00s' in!!

This is a discussion on strings with '00s' in!! within the C++ Programming forums, part of the General Programming Boards category; hi. I'm trying to adapt a program which uses strings of information to program into an external eeprom. Unfortunately, the ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    Question 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??

    (help)

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    Could you schow one of this strings please ...

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    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.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    A string like:

    char *eeprom_data = "8000";

    will work fine, as character zero is different from the string terminator.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    4
    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??

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    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.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    4
    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??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Problem with Strings, Please help!
    By varus in forum C++ Programming
    Replies: 8
    Last Post: 11-27-2006, 10:47 PM
  3. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  4. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21