RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 20713 | Replies: 5
Reply
Join Date: Jul 2005
Posts: 6
Reputation: pscha3 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pscha3 pscha3 is offline Offline
Newbie Poster

Help How do I use an array of structures?

  #1  
Jul 27th, 2005
When I wrote this program with a structures. I said:
	
{
		struct Contact
	{
		char Name[101];
		char Middle[101];
		char Last[101];
		long Area;
		long Area1;
		long Area2;
		long Area3;
		long Home;
		long Business;
		long Cell;
		long Other;
		char Email[101];
		char Address[101];
		int Zip;
		char City[101];
		char State[101];
		char Country[101];
		char Job[101];
		char Company[101];
	};
Contact hi[100];

Is this a right way of defining it? And how do I get the program to use the next structure every time?

I have another question. How do I Modify a file? I want to know how to do only a certain part of it like a certain structure?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,585
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 501
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: How do I use an array of structures?

  #2  
Jul 27th, 2005
>Is this a right way of defining it?
Every way is the right way as long as it compiles and does what you want. Your question can't be answered as asked.

>How do I Modify a file?
You read the file, make your changes in memory, then write the changed file back.
I'm here to prove you wrong.
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: How do I use an array of structures?

  #3  
Jul 27th, 2005
i usually use typedef and pointers with structs.

for file access use fopen(const char *, const char *)
Reply With Quote  
Join Date: Sep 2004
Posts: 6,585
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 501
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: How do I use an array of structures?

  #4  
Jul 27th, 2005
>i usually use typedef and pointers with structs.
>for file access use fopen(const char *, const char *)
The example code suggests C++, since C would fail to compile without the struct keyword. So both of your suggestions are poor ones.
I'm here to prove you wrong.
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: How do I use an array of structures?

  #5  
Jul 27th, 2005
hmm blunt.

Your right I like C and I don't like C++. I presumed it wouldn't compile in C++ too. But your right it does.

However, it also compiles with the struct keyword in C++ and fopen is available in C++.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,585
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 501
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: How do I use an array of structures?

  #6  
Jul 27th, 2005
>However, it also compiles with the struct keyword in C++ and fopen is available in C++.
Yes it does, but then again, so does malloc, and nobody in their right mind would advocate malloc in C++ most of the time. There are broad differences between good C and good C++, and using C solutions in C++ would be limiting yourself unnecessarily.
I'm here to prove you wrong.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:05 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC