Returning pointer to array problem

Discussion in 'C Programming' started by Carramba, Jun 2, 2005.

  1. Carramba

    Carramba Guest

    hi!

    Iam trying to make program were I enter string and serach char.
    and funktion prints out witch position char is found this
    is done if funktion serach_char. so far all good
    what I want do next is:
    return, from funktion, pointer value to array were
    positions ( of found char) is stored. and print that array from main.
    but I only manage to print memory adress to array..

    any suggestions?

    so far everything works fine.

    int search_char( char *pStr , char *pSearch );

    int main(void){
    char cStr[201];
    char cSearch[21];
    int *pInt;
    int i ;
    printf("Enter string\n",lillae);
    scanf("%s", cStr);
    printf("Enter char to sertch\n");
    scanf("%s", cSearch);
    *pInt = search_char( &cStr , &cSearch );
    printf("Main prints here:\n");
    for(i=0;i<20;i++){ //<== here problem starts
    printf("%d\n",&pInt);
    return 0;
    }

    int search_char( char *pStr , char *pSearch ) {
    printf("Funktion prints here:");
    int i;
    int vPossition[201];
    for( i=0;i<=200;i++){
    if(pStr == pSearch[0]){
    printf("Found %c in possition %d \n", pStr,i+1);
    vPossition = i; //<== here problem starts ????
    }
    }
    return vPossition;//<== here problem starts ???
    }

    --

    Thanx in advance
    ________________________
    BTW. I know my english is not best in the word, so please stop bugging me
    about my speling. And yes Iam sorry you don't understand what I mean, but
    there is no point to yell at me. Have a nice day.
     
    Carramba, Jun 2, 2005
    #1
    1. Advertisements



  2. Your code is poorly indented and the main function lacks the closing
    brace, so the program won't compile.
    Mixing statements and declarations of local variables is not allowed in
    standard C.



    -- August

    (If your native tongue is not a western language I will be indulgent.)
     
    August Karlstrom, Jun 2, 2005
    #2
    1. Advertisements

  3. Carramba

    Carramba Guest

    it's only copy and paste problem... so code ll compile

    don't realy understand what you mean... were do I do that?




    --

    Thanx in advance
    ________________________
    BTW. I know my english is not best in the word, so please stop bugging me
    about my speling. And yes Iam sorry you don't understand what I mean, but
    there is no point to yell at me. Have a nice day.
     
    Carramba, Jun 2, 2005
    #3
  4. Just before my comment. The `printf' statement comes before the `int i'
    declaration. All local variables must be declared before any statements
    in the function body.

    For instance, you haven't included stdio.h and you haven't declared the
    variable `lillae' in the `main' function so the program still won't
    compile. What compiler are you using??? Come back when you have
    something that compiles.


    -- August
     
    August Karlstrom, Jun 2, 2005
    #4
  5. It is allowed in C99. (It's also allowed in C++, which is relevant
    only if you're using a C++ compiler to compile your C code, which is
    usually a bad idea.)

    It's also allowed as an extension by some compilers; for example,
    "gcc -ansi" accepts it, but "gcc -ansi -pedantic" issues a warning.

    But if you care about portability to pre-C99 implementations, you
    should avoid using this feature.

    And August is correct, the code you posted cannot be compiled. We
    *might* be able to guess which errors are in your original code and
    which are the result of cut-and-paste errors, but it should be much
    easier for you to post your actual code than for us to play guessing
    games. Proper indentation will make it much easier to read, and make
    it much more likely that you'll get answers.

    It may seem like we're being overly picky, but we're really not.
    We're trying to help you to help us to help you.
     
    Keith Thompson, Jun 3, 2005
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.