LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-20-2009, 07:38 AM   #1
bizoo
LQ Newbie
 
Registered: Jul 2009
Posts: 17

Rep: Reputation: 0
Initializing a structure to Zero


Hi,
this particular question has been bugging me
I have a struct (small instance so not using code brackets )

struct random {
int a;
int b;
}example;

What i am trying is

example={0,0};

and it gives an error

Can someone help me how to initialize all the entries within a struct to zero?
In the above example i have used integers but what if they are some other data structure for example another structure?

many thanks!

cheers!
 
Old 11-20-2009, 07:46 AM   #2
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Slackware 13.0
Posts: 1,017

Rep: Reputation: 63
Quote:
Originally Posted by bizoo View Post
Hi,
this particular question has been bugging me
I have a struct (small instance so not using code brackets )

struct random {
int a;
int b;
}example;

What i am trying is

example={0,0};

and it gives an error

Can someone help me how to initialize all the entries within a struct to zero?
In the above example i have used integers but what if they are some other data structure for example another structure?

many thanks!

cheers!
Make an object of that structure ,
Code:
random obj;
obj.a=0;
obj.b=;
 
Old 11-20-2009, 07:59 AM   #3
Guttorm
Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 959

Rep: Reputation: 157Reputation: 157
Hi

struct random {
int a;
int b;
}example;

This code does two things. It defines a struct called "random", and it also defines a variable named "example". To initialize the variable, you can do:

struct random {
int a;
int b;
}example = {0,0};

You can use the struct to define other variables:
struct random example2 = {0,0};
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert directory structure from long file names in Linux to DOS 8.3 structure? manorina Linux - Software 5 09-12-2009 09:18 AM
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM
Initializing HAL mattnorb Linux - Software 7 05-29-2008 02:51 PM
ipw2100 not initializing leupi Linux - Wireless Networking 2 08-27-2005 10:44 PM
initializing the modem madhav.bnk Linux - Hardware 2 11-17-2004 11:17 PM


All times are GMT -5. The time now is 09:35 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration