String reversal,word by word

Write a C function to accomplish the word by word reversal of a string.That is if i give"hello world" it should give the output as "world hello"..







Regs
Progeni..

Comments

  • : Write a C function to accomplish the word by word reversal of a string.That is if i give"hello world" it should give the output as "world hello"..
    :
    :
    :
    :
    :
    :
    :
    : Regs
    : Progeni..
    :
    Not again...homework...what is your question exactly?

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


  • : Write a C function to accomplish the word by word reversal of a string.That is if i give"hello world" it should give the output as "world hello"..
    :
    :
    :
    :
    :
    :
    :
    : Regs
    : Progeni..
    :
    Here's a sollution:
    char* a = "hello world";
    char* tmp = " ";
    strcpy(tmp, a, 5);
    strcpy(a, a+6, 5);
    strcpy(a+6,tmp);
  • : : Write a C function to accomplish the word by word reversal of a string.That is if i give"hello world" it should give the output as "world hello"..
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : : Regs
    : : Progeni..
    : :
    : Here's a sollution:
    : char* a = "hello world";
    : char* tmp = " ";
    : strcpy(tmp, a, 5);
    : strcpy(a, a+6, 5);
    : strcpy(a+6,tmp);

    LOL!

    But you made a mistake...strcpy has only two arguments...you probably meant to use strncpy...

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


  • [b][red]This message was edited by IDK at 2006-5-22 8:53:24[/red][/b][hr]
    : LOL!
    :
    : But you made a mistake...strcpy has only two arguments...you probably meant to use strncpy...
    :
    : Greets,
    : Eric Goldstein
    : http://www.gvh-maatwerk.nl
    :
    :
    Yes, your right.
    [code]
    int main(){
    char* a = "hello world";
    char* tmp = " ";
    strcpy(tmp, a, 5);
    strcpy(a, a+6, 5);
    str[red]n[/red]cpy(a+6,tmp);

    return 0;
    }
    [/code]

    What if he gives this to his teacher?
  • : [b][red]This message was edited by IDK at 2006-5-22 8:53:24[/red][/b][hr]
    : : LOL!
    : :
    : : But you made a mistake...strcpy has only two arguments...you probably meant to use strncpy...
    : :
    : : Greets,
    : : Eric Goldstein
    : : http://www.gvh-maatwerk.nl
    : :
    : :
    : Yes, your right.
    : [code]
    : int main(){
    : char* a = "hello world";
    : char* tmp = " ";
    : strcpy(tmp, a, 5);
    : strcpy(a, a+6, 5);
    : str[red]n[/red]cpy(a+6,tmp);
    :
    : return 0;
    : }
    : [/code]
    :
    : What if he gives this to his teacher?
    : ok guys......
    what happens if i have *a= "strings1, string2, string3,....,stringn."
    the solution should be like to
    -have two counters
    -initialise the first to the first element
    -the second counter to the last
    -traverse through the array and count the number of strings
    -swap the first with the last
    -increment the first counter and decrement the last both by 1
    -call function swap again

  • : : ok guys......
    : what happens if i have *a= "strings1, string2, string3,....,stringn."
    : the solution should be like to
    : -have two counters
    : -initialise the first to the first element
    : -the second counter to the last
    : -traverse through the array and count the number of strings
    : -swap the first with the last
    : -increment the first counter and decrement the last both by 1
    : -call function swap again
    :
    I'm just having fun.
    This forum isn't for homework Q's, but he still gives them.
  • :
    : : : ok guys......
    : : what happens if i have *a= "strings1, string2, string3,....,stringn."
    : : the solution should be like to
    : : -have two counters
    : : -initialise the first to the first element
    : : -the second counter to the last
    : : -traverse through the array and count the number of strings
    : : -swap the first with the last
    : : -increment the first counter and decrement the last both by 1
    : : -call function swap again
    : :
    : I'm just having fun.
    : This forum isn't for homework Q's, but he still gives them.
    :


    [code]
    #include

    int main()
    {
    char str[] = "hello world";

    doHomeWork(str, 100);

    return 0;
    }
    [/code]

    BOOL doHomeWork (void* hwork, int delay);

    This general-purpose ANSI C function does any kind of homework.
    [hwork] is a pointer to the homework you need to do.
    [delay] is the number of milliseconds you wish to spend on it.
    It returns TRUE if you have learnt something from it, otherwise it returns FALSE.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories