I made 2 structures:
1. struct {} customer[100]
2. struct {} dummycustomer[100]
I need to put all the info in struct {} customer[100] to
struct {} dummycustomer[100].
My purpose is to use the dummy struct for sorting, since sorting would disarange the entries in the array. then I will again refer to the original struct.
Though a memcpy would work with the structures, I would not recommend you to do that as it would a bitwise copy (you would know what it is if you are familiar with that in classes and copy constructures).
Instead of create a dum copy of the entire array of structure I would use one dummy structure (better, a temp variable for each unique type in the structure) and swa the contents as needed.
For example, to swap the contents in a simple sort by your cid element, would look like:
long int tempLongInt;
char tempChar;
char tempString[40]; //take max size of string in your struct
float tempFloat;
for (i = 0, i < maxSize; i++) //where maxSize is of your array size
for (j = i+1; j < maxSize; j++)
if (customers[i].cid > customers[j] )
{
tempLongInt = customers[i].cid;
customers[i].cid = customers[j].cid;
customers[j].cid = tempLongInt;
// do it similarily for other long int variables such as prev, curr, cons
strcpy(tempStr, customers[i].fn);
strcpy(customers[i].fn, customers[j].fn);
strcpy(customers[j].fn, tempStr);
// do it similarily for other ln and addr too
Thats all. You dont have to create another 100 elements of dummy array where only a simple of temp variables or one dummy array of similar structure is enough.
Though a memcpy would work with the structures, I would not recommend that as it would be a bitwise copy (you would know what it is if you are familiar with classes and copy constructures in c++).
Instead of creating a dummy copy of the entire array of structure I would use one dummy structure of same type (better, a temp variable for each unique type in the structure) and swap the contents as needed.
For example, to swap the contents in a simple sort by your cid element, would look like:
long int tempLongInt;
char tempChar;
char tempString[40]; //take max size of string in your struct
float tempFloat;
for (i = 0, i < maxSize; i++) //where maxSize is of your array size
for (j = i+1; j < maxSize; j++)
if (customers[i].cid > customers[j].cid )
{
tempLongInt = customers[i].cid;
customers[i].cid = customers[j].cid;
customers[j].cid = tempLongInt;
// do it similarily for other long int variables such as prev, curr, cons
strcpy(tempStr, customers[i].fn);
strcpy(customers[i].fn, customers[j].fn);
strcpy(customers[j].fn, tempStr);
// do it similarily for other ln and addr too
Thats all. You dont have to create another 100 elements of dummy array where only a simple set of temp variables or one dummy array of similar structure is enough. That simple.
The codes you sent me were good but I had to make some adjustments.
I now have a problem with file processing, how to save a structure.
this is the code for my project. Anyone out there who can help will be much appreciated.