使用C函数(返回值)

编程入门 行业动态 更新时间:2024-10-13 14:22:51
本文介绍了使用C函数(返回值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

学习C和有很多疑惑。

我有一个函数(可以说功能1)调用另一个功能(可以说功能2)。函数2计算串的阵列

我如何使用这个数组在功能上1?

有些code例如:

INT find_errors(字符*字)    {        炭错误[100];        / *给定的话,它会发现重复字符,并将其存储在        错误数组。 * /       返回0;    }  INT find_word(字符*字)    {        find_errors(字);        的printf(%S \\ n,错误);        返回0;    }

解决方案

有至少有三种可能的方法:

  • 使用全局变量
  • 通过它们之间的参数
  • 从函数返回一个指针
  • Learning C and having many doubts.

    I have a function (lets say function 1) that calls another function (lets say function 2). Function 2 calculates an array of string.

    How can I use this array in function 1?

    Some code example:

    int find_errors(char* word) { char error[100]; /*Given the word, It will find the duplicate chars and store it in the error array. */ return 0; } int find_word(char* word) { find_errors (word); printf("%s\n", error); return 0; }

    解决方案

    There are at least three possible approaches:

  • Use a global variable
  • pass a parameter between them
  • return a pointer from the function
  • 更多推荐

    使用C函数(返回值)

    本文发布于:2023-11-26 02:29:55,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1632292.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:函数   返回值

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!