c - 函数 ‘peachy’ 的参数太少

标签 c

我一直在尝试练习使用参数和函数,但在这个基本尝试中我不断收到“参数太少错误”。谁能向我指出我需要做什么才能编译它?

#include <stdio.h>
#include <stdlib.h>

int peachy(char* str, int a, int b)
{
    str = "g";
    a = 7;
    b = 6;
    printf("Character: %s\n", str);
    printf("First Integer: %d\n", a);
    printf("Second Integer: %d\n", b);

}


int main(void)
{
    peachy();

}

最佳答案

像这样

#include <stdio.h>
#include <stdlib.h>

void peachy(char* str, int a, int b)
{
    printf("Character: %s\n", str);
    printf("First Integer: %d\n", a);
    printf("Second Integer: %d\n", b);

}


int main(void)
{
    peachy("g", 7, 6);
    peachy("foo", 42, 43); //just to show the use of function args    
}

关于c - 函数 ‘peachy’ 的参数太少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53182191/

相关文章:

c - 在 C 中将字符数组打印为十六进制

c++ - GetDIBits 帮助

c - 在 C 中连接字符串指针时如何避免内存泄漏

c - 读取 json 字符串时出现段错误

c - 将多维数组传递给函数并编辑值

c - 如何将部分字符串读入较小的字符串

c - 当我调试死锁情况消失时......那么我到底是怎么找到错误的呢?

C 如何将指针传递到文件中的位置以供读取

c - 如何找到对列表中所有有重叠的对?

c - 关系运算符在 printf 中使用时的输出行为 - C 语言