Thread: just a fuction problem

  1. #1
    Unregistered
    Guest

    just a fuction problem

    How can i make "Display" fuction work?
    thanks
    Code:
    #include <stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    //********* prototype******//
    void Display();
    struct info
          {
       	int test;
           };
    //*********M a i n **********/
    void main()
    {
    	struct info inf;
    	printf("Enter number :");
    	scanf("%d",&inf.test);
    	Display(inf.test);
    	//printf("\n show: %d",inf.test);
    	}
    //*******Function**************//
    void Display()
    {
    	struct info in;
    	printf("\n show: %d",in.test);
    }
    Thanks

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    It should be int main () instead of void main (). You forget to pass the structure to the function. Didn't your compiler give a warning/error about it?

    Code:
    void Display (struct info in);
    
    int main (void)
    {
        ...
        Display (in);
    
        return 0;
    }
    
    void Display (struct info in)
    {
        printf("\n show: %d",in.test);
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Didn't your compiler give a warning/error about it?
    Probably not

    It may have looked like a prototype, but it isn't really. It's just an old-style forward declaration.

    void Display();
    really means in C
    void Display(...);

    So all you can tell from this is that Display is a function - and that's it. You can pass any number of any parameters to it, and the compiler will say absolutely nothing about the correctness (or lack of).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with BST deletion
    By Mheso in forum C Programming
    Replies: 2
    Last Post: 02-24-2008, 11:23 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM