Recognise letters

Discussion in 'C' started by cquestion, Oct 25, 2007.

  1. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hello everybody, im new here. I am trying to make a program about chemistry periodic table. I have the following problem. The user has to tell the program a compound formula. For example HCl, and the program must tell the user it's name in words. I can make it with one letter formula's as H->Hydrogen, Na->Sodium. But when there are two letters, i can't sepparate them. For example. NaCl means sodium chloride, but i can't identify what is chloride and what is sodium when all the letters are together. What can I do?

    Thanks.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You should know the Rule of chemistry Cl will start with a capital letter and thats where you can detect the end of one element and start of second.
     
  3. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Oh, you are very witty shabbir. Thanks.
     
  4. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    I add two questions more, if anyone can help me. When i type scanf("%c" compound)
    and i write HCl, the program says 'overflow'. I know character constants can only accepts one letter, not three (as in HCl). How could i introduce this formula into the computer in order to analyse it's parts? (H and Cl). Also, which is the command that reads this? . I am very newbie in C :( I only know some commands, the most i've used is while and switch.
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You need to be using %s instead of %c and declare the variable as character array.
     
  6. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hello. I am very sorry for not having answered yet since your last answer. Thank you very much shabbir.
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    My pleasure
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice