如果我有这些功能:
void main(void)
{
char *menu[] = {"data", "coming", "here"};
prints(**************); // here
printf("\n");
}
void prints(char **menu)
{
int a;
while(*menu)
{
printf("%s", **menu);
menu ++;
}
a = 0;
}
如何调用打印函数???
最佳答案
这是修复了几个问题的版本:
#include <stdio.h>
// declare function before using it
void prints(char **menu)
{
// make sure parameter is valid
if (menu != NULL)
{
while(*menu)
{
// spaces so they don't run together
// pass *menu not **menu to printf
printf("%s ", *menu);
menu ++;
}
}
}
// proper return type for main()
int main(void)
{
// array terminator added
char *menu[] = {"data", "coming", "here", NULL};
prints(menu); // here
printf("\n");
// return with no error
return 0;
}
关于c - 调用函数有问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3314396/