Thread: how to convert char string to user defined data type

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    10

    how to convert char string to user defined data type

    I have the following piece of code,
    Code:
    typedef enum{ ArtsTheatre, NewArtsBlock, OpenAirTheatre}vertex;
    Now my problem is i want to convert char value into this vertex data type.How can i do that?
    suppose that user will input ArtsTheatre as char string.But in my program i want to covert into vertex data type.Any help would be appreciated.

    Thank you very much.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    - a series of if statements
    - a switch statement
    - a look-up table
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by prdeepss View Post
    Now my problem is i want to convert char value into this vertex data type.How can i do that?
    suppose that user will input ArtsTheatre as char string.But in my program i want to covert into vertex data type.
    I'm not sure if that makes very much sense; an enum contains a list of single integer values. Do you meant the user will enter a number, and you want that number assigned to ArtsTheatre? I think that will be awkward with an enum, you will have to do something convoluted like what Salem implies. I would use a struct instead.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    10
    Quote Originally Posted by Salem View Post
    - a series of if statements
    - a switch statement
    - a look-up table
    Thanks bro....

    I know brother it can be solved using IF , CASE statements. can i use strcmp method or how i do that. please explain me more clearly.

    thanks

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by prdeepss View Post
    Thanks bro....

    I know brother it can be solved using IF , CASE statements. can i use strcmp method or how i do that. please explain me more clearly.

    thanks
    You will have to put strcmp inside your if statements, yes. Note that you will not be able to use case statements to compare strings.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    10
    Thanks everybody.I got the right solution to my problem. I have used series of IF statement with strcmp method.

    Thanks everybody........

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM