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?

Recommended Answers

All 5 Replies

>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 usually use typedef and pointers with structs.

for file access use fopen(const char *, const char *)

>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.

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++.

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.