如何在c中将void函数(void)作为参数传递给另一个函数

-5 c parameters function-call function-declaration

[在此处输入图像描述][1]我有一个void readline()输出字符串的函数,我想将其作为参数传递给另一个函数,我该怎么做,

谢谢你的帮助。

int scorecount(argc1, argv1, void readline());
void readline();


int main(int argc, char *argv[]){
    scorecount(argc,argv);
}


int scorecount(argc1, argv1, void readline()){

    output a int
    and I want to use the string from readline function somewhere in
    scorecount

}


void readline(){

    output a string

}
Run Code Online (Sandbox Code Playgroud)

Vla*_*cow 5

您可以使用任何参数名称将参数声明为函数声明。例如

void another_function( void readline( void ) ); 
Run Code Online (Sandbox Code Playgroud)

该函数another_function可以这样调用

another_function( readline );
Run Code Online (Sandbox Code Playgroud)

编译器将函数声明调整为指向函数的指针。所以上面的声明等价于

void another_function( void ( *readline )( void ) ); 
Run Code Online (Sandbox Code Playgroud)

编辑:更新代码后,函数应该像这样声明

int scorecount( int argc, char * argv[], void readline( void ) );
void readline( void );
Run Code Online (Sandbox Code Playgroud)

并称其为

scorecount( argc, argv, readline );
Run Code Online (Sandbox Code Playgroud)