Like Tree1Likes
  • 1 Post By sparkomemphis

Help with the below program

This is a discussion on Help with the below program within the C Programming forums, part of the General Programming Boards category; The below program is not functioning properly I don't know if I have called the function "Integer" by passing its ...

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    India
    Posts
    12

    Help with the below program

    The below program is not functioning properly I don't know if I have called the function "Integer" by passing its address properly....Please help....


    insert
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    
    int integer()
    {
      int a;
      scanf("Enter the second number %d",&a);
      return a;
    }
    
    
    int subtract(int c, int (*q)())
    {
      int h;
      h = q; /*integer function called*/
      h = c - h;
      printf("%d",h);
      getch();
    }
    
    
    void main()
    {
      int a;
      scanf("Enter first integer %d", &a);
      int (*p)();
      p = integer; /*to store the address of integer function*/ 
      subtract(a,p); /*Passed the address of function to subtract*/
      getch();
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    Despite the comment, you did not actually call the function here:
    Code:
    h = q; /*integer function called*/
    Rather:
    Code:
    h = q(); /*integer function called*/
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    India
    Posts
    12
    k thank you......but if i woul have used

    insert
    Code:
      
    int *h;
    h = q; /*to store the address of integer function*/
    will this work without the braces ??

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    Quote Originally Posted by Dushyant
    will this work without the braces ??
    No, because h is a pointer to int, not a function pointer.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    66
    Code:
    nt integer()
    {
      int a;
      scanf("Enter the second number %d",&a);
     ...
    your scanf is looking for "Enter the second number [0-9]*" , that does not seem like a reasonable expiation for user input.
    AndiPersti likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-03-2009, 03:47 PM
  2. Get program to copy itself into program files, then start on startup.
    By guitarist809 in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2008, 08:42 AM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 12:11 PM
  5. How To Make The Program Installed In Program Files Folder?
    By javacvb in forum Windows Programming
    Replies: 4
    Last Post: 11-05-2003, 04:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21