Recognise letters

cquestion's Avatar
Go4Expert Member
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.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
cquestion's Avatar
Go4Expert Member
Oh, you are very witty shabbir. Thanks.
cquestion's Avatar
Go4Expert Member
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.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You need to be using %s instead of %c and declare the variable as character array.
cquestion's Avatar
Go4Expert Member
Hello. I am very sorry for not having answered yet since your last answer. Thank you very much shabbir.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by cquestion
Hello. I am very sorry for not having answered yet since your last answer. Thank you very much shabbir.
My pleasure