Looking for null terminator

This is a discussion on Looking for null terminator within the C Programming forums, part of the General Programming Boards category; When working with a character array: Code: char name[256] = ""; I normally check to see if it is a ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    13

    Looking for null terminator

    When working with a character array:

    Code:
    char name[256] = "";
    I normally check to see if it is a null string by:
    Code:
    if (name[0] == '\0') ...
    or I match along the string looking for '\0' when I parse strings some times.

    at times I might even do this:
    Code:
    switch (name[i])
    {
    case 'A':
    ...
    ...
    case 'B':
    ...
    ...
    }
    Question is, if now I declare name[256] as:
    Code:
    Tchar name[256]=L"";
    how should my code be changed accordingly, if I will be creating the app for use in both char and wchar_t cases?

    Thanks,

    MC

  2. #2
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    It will be the same for both char and widechars. What matters is the define UNICODE.

    The only things you should worry about is the size of your variable getting bigger. Wrapping all your string in _TEXT(). using %S identifeir for wide chars and %s for chars(UNICODE not defined).


    fine on both char and widechar
    Code:
    if (name[0] == '\0')
    Code:
    switch (name[i])
    {
    case 'A':
    ...
    ...
    case 'B':
    ...
    ...
    }

    *edited

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    13
    Thanks, just to make sure I don't need to do:

    Code:
    switch (name[i])
    {
    case L'A':
    ...
    ...
    case L'B':
    ...
    ...
    }
    Correct?

    MC

    Quote Originally Posted by loko
    It will be the same for both char and widechars. What matters is the define UNICODE.

    The only things you should worry about is the size of your variable getting bigger. Wrapping all your string in _TEXT(). using %S identifeir for wide chars and %s for chars(UNICODE not defined).


    fine on both char and widechar
    Code:
    if (name[0] == '\0')
    Code:
    switch (name[i])
    {
    case 'A':
    ...
    ...
    case 'B':
    ...
    ...
    }

    *edited

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    Quote Originally Posted by MiamiCuse
    Thanks, just to make sure I don't need to do:

    Code:
    switch (name[i])
    {
    case L'A':
    ...
    ...
    case L'B':
    ...
    ...
    }
    Correct?

    MC
    Just play it safe and do
    Code:
    switch (name[i])
    {
    case _T('A'):
    ...
    ...
    case _T('B'):
    ...
    ...
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminator 4
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-24-2009, 12:15 AM
  2. Removing null terminator from a string
    By Canadian0469 in forum C Programming
    Replies: 3
    Last Post: 10-27-2007, 03:03 PM
  3. Terminator 3..nope
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 07-18-2003, 08:42 AM

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