How do I use an array of structures?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 6
Reputation: pscha3 is an unknown quantity at this point 
Solved Threads: 0
pscha3 pscha3 is offline Offline
Newbie Poster

How do I use an array of structures?

 
0
  #1
Jul 27th, 2005
When I wrote this program with a structures. I said:
  1.  
  2. {
  3. struct Contact
  4. {
  5. char Name[101];
  6. char Middle[101];
  7. char Last[101];
  8. long Area;
  9. long Area1;
  10. long Area2;
  11. long Area3;
  12. long Home;
  13. long Business;
  14. long Cell;
  15. long Other;
  16. char Email[101];
  17. char Address[101];
  18. int Zip;
  19. char City[101];
  20. char State[101];
  21. char Country[101];
  22. char Job[101];
  23. char Company[101];
  24. };
  25. 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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,630
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 718
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How do I use an array of structures?

 
0
  #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 Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
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?

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

for file access use fopen(const char *, const char *)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,630
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 718
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How do I use an array of structures?

 
0
  #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 Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
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?

 
0
  #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 Quick reply to this message  
Join Date: Sep 2004
Posts: 7,630
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 718
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How do I use an array of structures?

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC