调用其他功能 [英] calling other functions

查看:44
本文介绍了调用其他功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道在另一个功能中从

调用功能的最佳方式。


说我已经获得了

int main(int argc,char * argv []){

返回0;

}


和另一个功能如:

void getInput(char name){

printf(" Hello");

....... ..........

}


我想要它,所以一旦程序启动就会直接进入到

getInput函数..


i试过;在主函数中:

getInput(char name);

void getInput(char name);

getInput;

getInput();


似乎没有工作


有什么想法吗?

感谢

解决方案

在文章< Ts **************** @ newsfep4-glfd.server.ntli .net>,Dilbert写道:

你好,只是想知道什么是从另一个功能中调用
函数的最好方法。

说我已经
int main(int argc,char * argv []){
返回0;
}
和另一个函数如:
void getInput(char姓名){
printf(" Hello");
.....................
}
<我希望它,所以一旦程序启动它就会直接进入
getInput函数..




你的getInput()函数需要一个角色作为其论点。

用角色称呼它。


#include< stdio.h>


void getInput(字符名称)

{

printf(" ;你好,得到''%c''\ n,名字);

}


int main(无效)

{

getInput(''Q'');

返回0;

}

-

Andreas K?h?ri


" Dilbert" <哈************ @ memail.com>写道:

我试过;在main函数中:
getInput(char name);
void getInput(char name);
getInput;
getInput();

似乎没有工作

任何想法?




是的。得到一本C书。我会推荐K& R.这真的是一个基本级别的问题,你应该在尝试新闻组和网络之前用语言熟悉一下(阅读:

all) br />
搜索。


提示:函数(实际参数),_ not_函数(类型)或

函数(声明)。


Richard




" Dilbert" <哈************ @ memail.com>在留言中写道

news:Ts **************** @ newsfep4-glfd.server.ntli.net ...

嗨那里,只是想知道在另一个函数中调用函数的最佳方法是什么。

说我已经得到了
int main(int argc,char * argv [] ){
返回0;
}

和另一个函数如:
void getInput(char name){
printf(" Hello") ;


这个printf()是一个函数,所以函数中的函数是

............... ......
}

我想要它,所以一旦程序启动它就会直接进入
getInput函数..
getInput(char name);
void getInput(char name);
getInput;
getInput();

似乎没有工作


getInput需要一个字符,现在这里有三个错误,

1)一个字符只能容纳一个字符,所以这应该接受一个char指针

或保存名称的char数组

2)函数名称没有暗示函数的作用,它叫做

getInput但实际上并没有得到任何输入。

3)你传递一个参数(字符名称)并且从未实际使用它


总而言之,我建议你得到你自己写了一本书(我不推荐K& R作为你的第一本书,但你应该最终阅读它),然后再研究一下



HTH

Allan


任何想法?
感谢



Hi there, was just wondering whats the best way to call a function from
within another function.

say ive got
int main (int argc, char * argv[]) {
return 0;
}

and another function such as:
void getInput(char name) {
printf("Hello");
.....................
}

and i wanted it, so as soon as the program starts it goes straight to the
getInput function..

i tried; in the main function:
getInput(char name);
void getInput(char name);
getInput;
getInput();

none seemed to work

Any ideas?
Thank

解决方案

In article <Ts****************@newsfep4-glfd.server.ntli.net>, Dilbert wrote:

Hi there, was just wondering whats the best way to call a function from
within another function.

say ive got
int main (int argc, char * argv[]) {
return 0;
}

and another function such as:
void getInput(char name) {
printf("Hello");
.....................
}

and i wanted it, so as soon as the program starts it goes straight to the
getInput function..



Your getInput() function expects a character as its argument.
Call it with a character.

#include <stdio.h>

void getInput(char name)
{
printf("Hello, got ''%c''\n", name);
}

int main(void)
{
getInput(''Q'');
return 0;
}
--
Andreas K?h?ri


"Dilbert" <Ha************@memail.com> wrote:

i tried; in the main function:
getInput(char name);
void getInput(char name);
getInput;
getInput();

none seemed to work

Any ideas?



Yes. Get a C book. I''d recommend K&R. This really is a question at such
a basic level that you should acquaint yourself a bit more (read: at
all) with the language before trying things like newsgroups and web
searches.

Hint: function(actual argument), _not_ function(type) or
function(declaration).

Richard



"Dilbert" <Ha************@memail.com> wrote in message
news:Ts****************@newsfep4-glfd.server.ntli.net...

Hi there, was just wondering whats the best way to call a function from
within another function.

say ive got
int main (int argc, char * argv[]) {
return 0;
}

and another function such as:
void getInput(char name) {
printf("Hello");
this printf() is a function, so thats a function within a function
.....................
}

and i wanted it, so as soon as the program starts it goes straight to the
getInput function..

i tried; in the main function:
getInput(char name);
void getInput(char name);
getInput;
getInput();

none seemed to work
getInput requires a char, now there are three things wrong here,
1) a char can only hold one character, so this should accept a char pointer
or a char array to hold a name
2) the function name does not hint what the function does, its called
getInput but doesnt actually get any input.
3) You pass a paramater (char name) and never actually use it

All in all, I suggest you get yourself a book in c (I dont recommend K&R as
your first book, but you should read it eventually), and study up a bit
more.
HTH
Allan


Any ideas?
Thank



这篇关于调用其他功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆