943,934 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 50279
  • C++ RSS
Jul 27th, 2005
0

How do I use an array of structures?

Expand Post »
When I wrote this program with a structures. I said:
C++ Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pscha3 is offline Offline
6 posts
since Jul 2005
Jul 27th, 2005
0

Re: How do I use an array of structures?

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 27th, 2005
0

Re: How do I use an array of structures?

i usually use typedef and pointers with structs.

for file access use fopen(const char *, const char *)
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Jul 27th, 2005
0

Re: How do I use an array of structures?

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 27th, 2005
0

Re: How do I use an array of structures?

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++.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Jul 27th, 2005
0

Re: How do I use an array of structures?

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ question and some guidance
Next Thread in C++ Forum Timeline: Problem with Character Arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC