having trouble programming

This is a discussion on having trouble programming within the C Programming forums, part of the General Programming Boards category; hello, im just a beginner and im having problems in printing out string in reverse, can you give me an ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    3

    Question having trouble programming

    hello, im just a beginner and im having problems in printing out string in reverse, can you give me an example as to how i can print helloworld in the format dlrowolleh?? it will be much appreciated!! thankyou!!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,655
    > im having problems in printing out string in reverse
    Such as?
    What have you tried to do so far?

    Can you - for example - print a string out one character at a time forwards?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    3

    trouble programming

    yes i can print out the string hello world forwards, but i cant figure out the for function to print it in reverse,

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,655
    how about
    for ( i = strlen(msg ) ; i >= 0 ; i-- )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User breed's Avatar
    Join Date
    Oct 2001
    Posts
    91
    Or try this !

    void main()
    {
    char *alphabet = {" the alphabet"};
    char *coded + {"the alphabet in reverse"};

    char message[50];
    char *m_ptr = message,
    *a_ptr = alphabet,
    *c_ptr = code;

    printf("\nEnter message");
    gets(message);

    while( *m_ptr)
    {
    while( *m_ptr != *a_ptr++ )
    c_ptr++;

    *m_ptr = *c_ptr;
    a_ptr = alphabet;
    c_ptr = code;
    }

    printf("\nthe message was > %s", message);
    }


    another compy lesson
    Before you judge a man, walk a mile in his
    shoes. After that, who cares.. He's a mile away and you've got
    his shoes.
    ************William Connoly

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Me too, me too! I want to do their homework!!
    [code]
    #include <stdio.h>
    #include <string.h>
    int main(void){char b[1024]={0},c;int x,y;fputs("Enter a string:",stdout);fgets(b,1024,stdin);for(x=0,y=str len(b)-1;
    x<strlen(b)>>1;x++){c=b[x];b[x]=b[y-x];b[y-x]=c;}fputs(b,stdout);return!1;}
    [\code]
    Teachers appreciate compact code.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User breed's Avatar
    Join Date
    Oct 2001
    Posts
    91

    Red face

    K!!!

    is this anomosity?

    say what you mean why don't you.

    Before you judge a man, walk a mile in his
    shoes. After that, who cares.. He's a mile away and you've got
    his shoes.
    ************William Connoly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 02:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 03:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 11:58 AM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2003, 11:55 PM

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