help......i dont understand what i am doing wrong?

This is a discussion on help......i dont understand what i am doing wrong? within the C Programming forums, part of the General Programming Boards category; I am trying to write a programed named reverse.c that echoes its command-line arguments in reverse order. But i don't ...

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

    help......i dont understand what i am doing wrong?

    I am trying to write a programed named reverse.c that echoes its command-line arguments in reverse order. But i don't know what is wrong.
    If the input is: reverse void and null
    The output should be: null and void

    Code:
     #include <stdio.h> 
     #define N 100 
    
      main(int argx, char *argy[])
     { int i=0, k; 
        char *p[100]; 
      
        printf("Enter a sentence: "); 
        gets(argy[100]); 
        i++; 
        for(k = i-1; k >= 0; k--)
        printf("%s", argy[0]); 
    
        return 0; 
      }
    Code tags added by Kermi3.

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    Code Tags

    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.

    Good Luck,
    Kermi3
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Sorry to say, but you don't seem to understand the command line concept.

    Here's some pseudo code to help you out.

    check number of arguments
    then simply print the strings from the last to the 1st argument using the above info

    Questions to consider
    - How do I know what the last string is?
    - Where is the first string?

    You can code this without declaring any variables.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

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