Thread: if statement

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    4

    if statement

    im trying to use an if statement on a string. is there a way that if i say scanf("%s", &user) that i can then proceed to say if (user== quit) then....... 'quit' doesnt work because that is for characters any ideas?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Use strcmp()

    > scanf("%s", &user)
    If you have a char array, then drop the &, you don't need it.
    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
    Registered User
    Join Date
    Jul 2006
    Posts
    4
    i am scanning in as an array using a for loop, i just said scanf for simplicity.... strncmp compares two strings im trying to see if the word that was entered by the user is "quit" should i use strncmp and define quit up above main?

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    4
    nevermind im retarded, i got it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM