使用C函数(返回值) [英] using functions in c (return value)
本文介绍了使用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函数(返回值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文