strings

This is a discussion on strings within the C Programming forums, part of the General Programming Boards category; Hello there, I am trying to write the algorithm for a program that will return 1 (true) if a string ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    15

    strings

    Hello there,

    I am trying to write the algorithm for a program that will return 1 (true) if a string argument ends in the substring OH.

    I'm pretty confused, even though it seems fairly simple.

    Would I accomplish this with an if statement?

    something like:

    Code:
     if string [i] = 'O' && string [i+1] = 'H'
    
    return TRUE;
    
    else return FALSE;
    Thanks!

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Be wary there is no such thing as TRUE and FALSE in C unless you define it yourself. Also your if statement is improperly formed. You should probably look into strstr() and strcmp() for the operation you requested.

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    A regular expression would be the least amount of code to write.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,058
    you have got it down pat and the next step would be to go from pseudo-code to code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 07:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 03:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 12:23 PM

Tags for this Thread


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