Thread: Problems with Struct

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    Problems with Struct

    Hey, how can I make a type of structure global? for example the code below does not compile.

    Code:
    struct sponsor
    {
    	HBITMAP banner;
    	char bannerSite[150];
    };
    sponsor add;
    add.banner = NULL;
    add.banner = "www.google.com"
    Instead I have to do something like:

    Code:
    struct sponsor
    {
    	HBITMAP banner;
    	char bannerSite[150];
    };
    
    int main()
    {
    	sponsor add;
    	add.banner = NULL;
    	add.bannerSite = "www.google.com";
    }
    Anyways if I can't do whats in the first example how can I make add global?

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    You have to initialize the struct inside main or whatever function you like to call. But the variable can be declared outside the function.

    Code:
    struct sponsor
    {
    	HBITMAP banner;
    	char bannerSite[150];
    };
    sponsor add;
    
    void main()
    {
    	add.banner = NULL;
    	add.bannerSite = "www.google.com";
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  2. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  3. weird typedef struct problems
    By olidem in forum C Programming
    Replies: 3
    Last Post: 07-28-2008, 02:59 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM