所以我为我的C类创建了这个程序,它可以创建一个函数来告诉你字符串中某个数字位置的字符.
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;
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,在我使用命令行运行它时没有显示错误
name charAt string 3
Run Code Online (Sandbox Code Playgroud)
它崩溃了
printf( "%s", charAt( argv[2], pos) );
Run Code Online (Sandbox Code Playgroud)
那一行为什么当我将char指针传递给printf函数时它会崩溃?
c ×1