Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Recognise letters (http://www.go4expert.com/forums/recognise-letters-t7039/)

cquestion 25Oct2007 19:12

Recognise letters
 
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 25Oct2007 19:40

Re: Recognise letters
 
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 25Oct2007 20:01

Re: Recognise letters
 
Oh, you are very witty shabbir. Thanks.

cquestion 25Oct2007 20:06

Re: Recognise letters
 
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 25Oct2007 20:27

Re: Recognise letters
 
You need to be using %s instead of %c and declare the variable as character array.

cquestion 12Nov2007 02:13

Re: Recognise letters
 
Hello. I am very sorry for not having answered yet since your last answer. Thank you very much shabbir.

shabbir 12Nov2007 10:31

Re: Recognise letters
 
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


All times are GMT +5.5. The time now is 01:31.