Thread: arrays

  1. #1
    Registered User
    Join Date
    Sep 2001

    Cool arrays

    Im new at C programming and im confused can someone please help. I would really appreciate. thank you.
    I have to write a program which will reverse the order of the letters in the words. Each line should have a limit of 100 chars

    So if you have a input like : uoy knaht
    the output would be : thank you

    this is what i have :

    void reverse_line(char[line], char lim)
    int i, state;

    for(i =0; i <lim; i++)
    if( line[i] != ' ')

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    I think the best thing to do is work with a string function that'll append one character to the beginning of the string. So it'll see 'u' and your string will be "u". Then it'll see 'o' and append it as first character and you'll have "ou" and so forth.
    1978 Silver Anniversary Corvette

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Sorry, I can't quite find the function that I'm thinking of that'll append one character to a specific place (the beginning of the string, in out case). I'll keep looking.
    1978 Silver Anniversary Corvette

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    in pseudocode....

    1) you need two pointers and a tempory holding variable.
    2) use strlen to work out the length of the string.
    3) make pointer1 point at the start char of the string.
    4) make pointer2 point to the last char before the null byte.You know where this is because you know how long the string is.
    5) inside a while loop (pointer1<pointer2)
    i) place first char in holding area
    ii) place last char in first chars place.
    iii) place char in holding area in last chars space.
    iv) add 1 to pointer1
    v) decrement pointer2

    This will reverse your string leaving the null byte untouched.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM