Home Forums C Programming Reading input string

Viewing 2 reply threads
  • Author
    Posts
    • #2105
      Arunkumar.N
      Participant

      Hello,
      I’m pretty new to C so if you think i’m going about this completely wrong, please tell me so. I’ve looked through multiple tutorial sites, but im still not certain how i need to go about this. Basically what I am trying to do is create a periodic table program for the command line, first it draws a text only periodic table, then it asks the user to input the chemical symbol an element. What im wanting it to do is after it gets the input, is to go to a part in the program and print information about the element to the terminal. I just don’t know how to compare the strings, to the preset element symbols. I was thinking i would have to use either a If stament or switches? is there any way to do this, or am i taking the wrong approach? I’m sorry if i don’t make much sense right now.

      Thanks,
      Nathan

      Edit – I figgured out how to do what i was needing to do, so i’ll post a simple version of what a came up with. And i should probably give credit to http://www.cprogramming.com/ for the function to remove the null terminator.

    • #3397
      Humayan
      Participant

      To compare to strings I would use strcmp() from string.h , check out this link:

      http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html

    • #3398
      Adetutu
      Participant

      Actually your code is right. However from your messgae it is not clear what the problem is?
       
      Well check the herader file name. It must be second opening curley braces ({) after main().
       
      Kindly wirite specific problem

Viewing 2 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.