简体   繁体   English

void 函数不返回任何内容 - C

[英]void function returns nothing - C

I'm starting my studies in C and i came across this function return problem.我开始学习 C 语言,但遇到了这个函数返回问题。 I created a function that prints the name of numbers up to 9, from an input number.我创建了一个函数,可以从输入的数字中打印最多 9 的数字名称。 Entering, i have no return from the function.进入,我没有从函数中返回。 I can't see where the error is.我看不到错误在哪里。

This is my code:这是我的代码:

void for_loop(int n1, char array[]){
    for(int index = n1; index <= 9; index++) {
        printf("%s\n", array[index]);
    }
}

int main() 
{
    int num1 = 2;

    char* numbers[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    for_loop(num1, *numbers);
    return 0;
}

Your code is wrong:你的代码是错误的:

You want this:你要这个:

void for_loop(int n1, char *array[]) {
  for (int index = n1; index <= 9; index++) {
    printf("%s\n", array[index]);
  }
}

int main()
{
  int num1 = 2;

  char* numbers[10] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

  for_loop(num1, numbers);
  return 0;
}

for_loop(num1, *numbers) is equivalent to for_loop(num1, numbers[0]) which is equivalent to for_loop(num1, "zero") . for_loop(num1, *numbers)相当于for_loop(num1, numbers[0]) ,相当于for_loop(num1, "zero")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM