So i have this program for my C class its to make a function that will tell you the character at a certain number position in the string.
char charAt( char * string, int position );
int main( int argc, char * argv[ ] ) {
int pos = atoi( argv[3] );
if( strcmp( argv[1], "charAt" ) == 0 )
{
printf( "%s", charAt( argv[2], pos ) );
}
}
char charAt( char *string, int position ){
int count = 0;
while( count != position ){
string++;
count++;
}
return *string;
}
When i compile it shows no errors when i run it in the command line using
name charAt string 3
It crashes at
printf( "%s", charAt( argv[2], pos) );
that line Why when i pass the char pointer to the printf function does it crash?