Like Tree1Likes
  • 1 Post By Adak

character array - sentinel value

This is a discussion on character array - sentinel value within the C Programming forums, part of the General Programming Boards category; I'm fairly new to C programing and I've been working on developing a program that will allow the user to ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    4

    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:

    Input:
    New York

    Output:
    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?

    Thanks!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.
    Code:
    if(strcmp(string1,"stop")== 0) {
       break;   //break out of the current loop
    }
    avolkmar likes this.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    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, 03: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, 11:57 AM
  5. Replies: 2
    Last Post: 03-12-2002, 02:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21