just a fuction problem

This is a discussion on just a fuction problem within the C Programming forums, part of the General Programming Boards category; How can i make "Display" fuction work? thanks Code: #include <stdio.h> #include<string.h> #include<stdlib.h> //********* prototype******// void Display(); struct info { ...

  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,386
    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
    32,854
    > 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, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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