Thread: need help 6

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    6

    need help 6

    I have program here from msdn.
    my problem is how to get output such as "fox" or when read backward output such as "over the". what syntax or commnad i need to use.

    /* STRSTR.C */

    #include <string.h>
    #include <stdio.h>

    char str[] = "lazy";
    char string[] = "The quick brown dog jumps over the lazy fox";
    char fmt1[] = " 1 2 3 4 5";
    char fmt2[] = "1234567890123456789012345678901234567890123456789 0";

    void main( void )
    {
    char *pdest;
    int result;
    printf( "String to be searched:\n\t%s\n", string );
    printf( "\t%s\n\t%s\n\n", fmt1, fmt2 );
    pdest = strstr( string, str );
    result = pdest - string + 1;
    if( pdest != NULL )
    printf( "%s found at position %d\n\n", str, result );
    else
    printf( "%s not found\n", str );
    }


    Output

    String to be searched:
    The quick brown dog jumps over the lazy fox
    1 2 3 4 5
    12345678901234567890123456789012345678901234567890

    lazy found at position 36


    sample output i need when found position "lazy" at 36 then
    output such as:

    in front of lazy word is: fox
    2 step backward is: over the

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    sample output i need when found position "lazy" at 36 then
    output such as:

    in front of lazy word is: fox
    2 step backward is: over the
    Start by moving forward from 36 until the first character after a space and print that word, then move backward from 36 until you've counted two spaces. Print the two words.

    And don't use void main, MSDN is wrong there.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed