Thread: Strings: Simple

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    110

    Strings: Simple

    Hello,

    My job is to have a character string called word[4] and to guess what my teacher put in...

    So if he puts in DONE for word[4] (caps only) my loop has to keep putting in letters till it matches DONE


    im kind of lost so how do U assign the 3 palce of a string a letter ?

    char1 = 65;
    word[3] = char1;


    Im pretty lost we have to use a loop to go through every ANSII character.

  2. #2
    Registered User loopy's Avatar
    Join Date
    Mar 2002
    Posts
    172
    You could use:

    Code:
    char alpha[] = {'a', 'b', 'c'...etc
    And loop through that array, checking for a correct character.

    Loopy

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Set up a loop for each of his characters
    Set up another loop for letters from 'A' to 'Z'
    test his character
    If his character matches the letter, do what you need to do
    Next letter
    Next character
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Strings: Simple

    Originally posted by Coder87C
    My job is to have a character string called word[4] and to guess what my teacher put in...

    So if he puts in DONE for word[4] (caps only) my loop has to keep putting in letters till it matches DONE
    It's only a "string" if it's \0 terminated, which in your case it isn't, therefore you're talking about an array of type char.

    If you want a string, you need one extra byte to store the \0, and you'd use it like so:
    Code:
    char myword[5];
    strcpy (myword, "DONE");
    
    /* OR */
    char myword[] = "DONE";
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple question about strings
    By panfilero in forum C Programming
    Replies: 2
    Last Post: 11-03-2005, 01:57 AM
  2. Radix Sort, Strings, and Linked Lists
    By dark paladin in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2003, 03:24 PM
  3. converting c style strings to c++ strings
    By fbplayr78 in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 03:13 AM
  4. strings strings strings str..
    By Linette in forum C++ Programming
    Replies: 1
    Last Post: 02-17-2002, 02:12 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM