Thread: character array - sentinel value

  1. #1
    Registered User
    Join Date
    Oct 2012

    character array - sentinel value

    I'm fairly new to C programing and I've been working on developing a program that will allow the user to input in some word and output the word backwards. For example:

    New York

    korY weN

    I'm having no trouble doing this, but I want the program to run on a loop and exit when the word "stop" is entered. Any suggestions?


  2. #2
    Registered User
    Join Date
    Sep 2006
    Welcome to the forum, avolkmar!

    String comparisons in C are done with the strcmp(string1, string2) function. Include the header file <string.h> to use it. The return from strcmp() works like this:

    Value > 0 = strcmp(string1, string2) (string1 > string2)
    Value < 0 = strcmp(string1, string2) (string1 < string2)
    Value of 0 = strcmp(string1, string2) (string1 ==s tring2)

    Just remember that the value returned will refer to string1, When string1 is greater, the value returned will be > 0, etc.
    if(strcmp(string1,"stop")== 0) {
       break;   //break out of the current loop

  3. #3
    Registered User
    Join Date
    Oct 2012
    Just tried it and it works great! Thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I remove a character from character array?
    By nick753 in forum C++ Programming
    Replies: 25
    Last Post: 12-08-2010, 11:27 AM
  2. Replies: 15
    Last Post: 09-23-2010, 02:19 PM
  3. REmoving a character from a character array
    By Bladactania in forum C Programming
    Replies: 3
    Last Post: 02-11-2009, 02:59 PM
  4. Replies: 7
    Last Post: 05-11-2008, 10:57 AM
  5. Replies: 2
    Last Post: 03-12-2002, 02:32 PM