dimanche 30 octobre 2016

Passing pointers through for loops and if statements

I am trying to pass a pointer through this for loop but it doesn't work. This is just a block from my original code. I didn't want to overload you all with 200 lines of code! If you need all of it please ask.

Ok! so I used 3 printf's to see how far my code gets before it crashes. It gets to the printf( "2" ); before it crashes. So I am assuming it is something to do with "if ( *(userInput + i ) == sNumArray[j] )" I am not sure what I am doing wrong. As far as I know pointers dont use pointer[i] to cycle through each element they use *( pointer + i )?

I only started programming with c 4 weeks ago so sorry if I didn't explain this thoroughly. I am still learning the terminology etc

for ( i = 0; i < sUserInput_SIZE; i++ ) {

        printf( "1" );

    for( j = 0; j < sNumArray_SIZE; j++ ) {

        printf( "2" );

        if ( *(userInput + i ) == sNumArray[j] ) {

            validInput++;
            printf( "3" );

        }//End if( )

    }//End inner for( )

}//End outer for( )

Aucun commentaire:

Enregistrer un commentaire