function pointers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • munni

    #1

    function pointers

    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

  • Ian Collins

    #2
    Re: function pointers

    munni wrote:[color=blue]
    > 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
    >[/color]
    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.
    --
    Ian Collins.

    Comment

    • santosh

      #3
      Re: function pointers


      munni wrote:[color=blue]
      > 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.[/color]

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

      Comment

      • ramu

        #4
        Re: function pointers

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

        Comment

        • John Bode

          #5
          Re: function pointers


          munni wrote:[color=blue]
          > 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[/color]

          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[i])();

          or

          x = f[i]();

          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.

          Comment

          • Jirka Klaue

            #6
            Re: function pointers

            John Bode:
            [color=blue]
            > 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.[/color]

            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

            Comment

            • munni

              #7
              Re: function pointers

              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

              Comment

              • munni

                #8
                Re: function pointers

                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

                Comment

                • Keith Thompson

                  #9
                  Re: function pointers

                  "munni" <munnilone@yaho o.com> writes:[color=blue]
                  > 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.[/color]

                  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.

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                  We must do something. This is something. Therefore, we must do this.

                  Comment

                  • Ian Collins

                    #10
                    Re: function pointers

                    munni wrote:[color=blue]
                    > 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
                    >[/color]
                    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.

                    --
                    Ian Collins.

                    Comment

                    • munni

                      #11
                      Re: function pointers


                      Keith Thompson wrote:[color=blue]
                      > "munni" <munnilone@yaho o.com> writes:[color=green]
                      > > 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.[/color]
                      >
                      > 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.
                      >
                      > --
                      > Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                      > San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>[/color]

                      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
                      [color=blue]
                      > We must do something. This is something. Therefore, we must do this.[/color]

                      Comment

                      • CBFalconer

                        #12
                        Re: function pointers

                        munni wrote:[color=blue][color=green]
                        >> "munni" <munnilone@yaho o.com> writes:[/color]
                        >[color=green][color=darkred]
                        >>> " There r 26 functions. and i need to write a program so that what[/color][/color][/color]
                        ^ ^
                        gobbledegook more gobbledegook[color=blue]
                        >[/color]
                        .... snip ...[color=blue]
                        >
                        > i dont want u to give me the code. i want u to give me some[/color]
                        ^ ^ ^ ^
                        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.

                        --
                        "A man who is right every time is not likely to do very much."
                        -- Francis Crick, co-discover of DNA
                        "There is nothing more amazing than stupidity in action."
                        -- Thomas Matthews


                        Comment

                        • Jordan Abel

                          #13
                          Re: function pointers

                          On 2006-02-09, CBFalconer <cbfalconer@yah oo.com> wrote:[color=blue]
                          > munni wrote:[color=green][color=darkred]
                          >>> "munni" <munnilone@yaho o.com> writes:[/color]
                          >>[color=darkred]
                          >>>> " There r 26 functions. and i need to write a program so that what[/color][/color]
                          > ^ ^
                          > gobbledegook more gobbledegook[/color]

                          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.]

                          Comment

                          • Keith Thompson

                            #14
                            Re: function pointers

                            Jordan Abel <random832@gmai l.com> writes:[color=blue]
                            > On 2006-02-09, CBFalconer <cbfalconer@yah oo.com> wrote:[color=green]
                            >> munni wrote:[color=darkred]
                            >>>> "munni" <munnilone@yaho o.com> writes:
                            >>>
                            >>>>> " There r 26 functions. and i need to write a program so that what[/color]
                            >> ^ ^
                            >> gobbledegook more gobbledegook[/color]
                            >
                            > 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.][/color]

                            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.

                            --
                            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                            We must do something. This is something. Therefore, we must do this.

                            Comment

                            Working...