function pointers

M

munni

hi
i want to write a program on function pointers where i have not
written any programs using function pointers till now. i want to take
an array of 26 functions which r to be pointed by this pointer. pls
give me an example to write a program.
thanking u in
advance
munni
 
I

Ian Collins

munni said:
hi
i want to write a program on function pointers where i have not
written any programs using function pointers till now. i want to take
an array of 26 functions which r to be pointed by this pointer. pls
give me an example to write a program.
thanking u in
advance
munni
If you,re going to post here, please use English, not txt speak.

Show us what you know and how you think you should start.
 
S

santosh

munni said:
hi
i want to write a program on function pointers where i have not
written any programs using function pointers till now. i want to take
an array of 26 functions which r to be pointed by this pointer. pls
give me an example to write a program.

Array of functions does not exist at least in C language. Please be
more specific with your question.
 
R

ramu

You can't take an array of functions. AFAIK, there is no such facility
in c. You can have an array of function pointers.
 
J

John Bode

munni said:
hi
i want to write a program on function pointers where i have not
written any programs using function pointers till now. i want to take
an array of 26 functions which r to be pointed by this pointer. pls
give me an example to write a program.
thanking u in
advance
munni

You cannot create an array of 26 functions. You *can* create an array
of 26 function pointers:

int (*f[26])(void)

f is a 26-element array of pointers to functions taking no parameters
and returning int. To call each function you'd write:

x = (*f)();

or

x = f();

You assign each element using the name of the function to be pointed
to. For example, given:

int foo(void) {...}

you'd assign an array element like

f[0] = foo;

Note that you cannot have an array of pointers to functions of
different signatures; all the functions pointed to by the array must
take the same number and type of parameters and must have the same
return type.
 
J

Jirka Klaue

John Bode:
Note that you cannot have an array of pointers to functions of
different signatures; all the functions pointed to by the array must
take the same number and type of parameters and must have the same
return type.

However, it is possible to cast different function pointer types
to the one declared in the array. To call the functions, you have
to cast them back to their original type.

void (*f[26])(void);

f[0] = (void (*)(void))sin;
double x = ((double (*)(double))f[0])(177.5/113);

Jirka
 
M

munni

hi
my question is not array of functions but array of function
pointers. i have a program that
" There r 26 functions. and i need to write a program so that what
ever function i want to call i should enter it , and that function
should be called. This should be done by using function pointers.
More clearly, if i enter c, c function should be called and
if i enter k , kfunction should be called. pls tell me how to write the
program.
i am not at all getting any idea of how to write it.
waiting for reply
munni
 
M

munni

hi
a little correction. i want to take an array of function
pointers.
pls look at the following question whic i was asked to answere.
"There r 26 functions. a-z. i need to call what ever function i
like.
for example, if i enter c, c() should be called. if i enter k,
k() should
get called. this i need to do using function pointers. pls help
me in this
thanking u in
advance

munni
 
K

Keith Thompson

munni said:
my question is not array of functions but array of function
pointers. i have a program that
" There r 26 functions. and i need to write a program so that what
ever function i want to call i should enter it , and that function
should be called. This should be done by using function pointers.
More clearly, if i enter c, c function should be called and
if i enter k , kfunction should be called. pls tell me how to write the
program.
i am not at all getting any idea of how to write it.

So you want us to do your homework for you?

Try writing it yourself. Ask your instructor. If you run into
problems with your code, let us know.
 
I

Ian Collins

munni said:
hi
a little correction. i want to take an array of function
pointers.
pls look at the following question whic i was asked to answere.
"There r 26 functions. a-z. i need to call what ever function i
like.
for example, if i enter c, c() should be called. if i enter k,
k() should
get called. this i need to do using function pointers. pls help
me in this
thanking u in
advance

munni
You've had several responses telling you we don't do homework and to
post some code.

Also please stop the text speak and responding random posts.
 
M

munni

Keith said:
So you want us to do your homework for you?

Try writing it yourself. Ask your instructor. If you run into
problems with your code, let us know.

hello sir,
i dont want u to give me the code. i want u to give me some
idea of how to start.
moreover now no need. i got it.
munni
 
C

CBFalconer

^ ^
gobbledegook more gobbledegook
.... snip ...

i dont want u to give me the code. i want u to give me some
^ ^ ^ ^
lots more gobbledegook and still more here

Why do you insist on offending the very people you are asking to
help you? These silly abbreviations are not acceptable. This is
pure rude carelessness, not a language barrier.
 
J

Jordan Abel

^ ^
gobbledegook more gobbledegook

You know - some people have an objection to the bizarre practice of
capitalizing "i" on grounds other than wanting to save half a keystroke.
[I suspect the original poster isn't such a person, but all the same
please save your objection for the "u"s and "r"s.]
 
K

Keith Thompson

Jordan Abel said:
^ ^
gobbledegook more gobbledegook

You know - some people have an objection to the bizarre practice of
capitalizing "i" on grounds other than wanting to save half a keystroke.
[I suspect the original poster isn't such a person, but all the same
please save your objection for the "u"s and "r"s.]

That "bizarre practice" is standard English grammar. I agree that a
lot of English grammar is bizarre, but spelling "I" and "i" causes
just as much difficulty as spelling "you" as "u".

Thuh lak uv fonetik speling iz bizar tu, but we should continue to use
standard spelling until and unless the language is changed.

Until and unless someone actually states a reasonable objection to
capitalizing "I", I suggest we use and encourage standard English
rather than making excuses for bad usage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,489
Latest member
BrigidaD91

Latest Threads

Top