Thread: How to assign ';' to a char?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    How to assign ';' to a char?

    Neither
    Code:
    char c = ';' ;
    or
    Code:
    char c = '\;' ;
    works.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The first one works fine and is correct. What problem are you having?

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    52
    Try char c = 59; //Where 59 = ascii code of ';'

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    > Try char c = 59; //Where 59 = ascii code of ';'

    Don't do that. That makes it dependent on a particular character set.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by meili100 View Post
    Neither
    Code:
    char c = ';' ;
    or
    Code:
    char c = '\;' ;
    works.
    You probably have something else wrong in the code. The first one is correct and should work with any reasonable compiler. How do you think the compiler would compile itself if it couldn't cope with semicolons in quotes? It is kind of an important separator in the parser, so there will be more than one place doing something like:
    Code:
    if (ch == ';') ...
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM