c - 调用函数有问题?

标签 c

如果我有这些功能:

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/

相关文章:

c - setlocale 在返回非 NULL 值时引发 errno

c - 如何使用 libxml2 解析 XML 中的数据?

java - 将数组作为指针+大小或范围传递给包装的函数

c - 用 "U"指定无符号整数有什么意义?

C编程。为什么函数指针会破坏优化

c - 在数组初始值设定项列表中提供的初始值设定项是否多于数组中的元素是语法错误吗?

c、从头开始shrink分配的空间

c - 我如何使用linux在c中使用fork()来实现我想要的输出?

c - 为什么局部变量不匹配全零条件?

c - 为什么我的 C 二进制到十进制程序没有返回正确的值?