Adding sales and customers to a database

I have been given an assignment in persistent data(Language C), basically i had to be able to search for a customer or a sale which i think i have done, and convert that text file to a binary file. Now im just wondering how to add a sale or customer to the file.. Any help would be apreciated or comments on my code so far because im a bit rusty with it..

[CODE]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct customer
{
int id;
char first_name[40];
char surname[40];
int age;
char gender[7];
char address[100];
};

struct sales
{
char customer_id;
int id;
char product_description[100];
float price;
int quantity;
};

struct customer new_customer;
struct sales new_sale;

void search(void);
void binary(void);
void add_customer(void);
void add_sale(void);
main()
{
FILE* fp;

fp=fopen("customers.txt","rb");

if(!fp)
{
printf("unable to open file\n");
}

int num1, num2, num3, num4;

printf("Please enter\n1. to search a customer or sale\n2. to add a customer\n3. to add a sale\n4. binary search\n");
scanf("%5d", &num1, &num2, &num3, &num4);

if(num1)
{
search();
}
else if(num2)
{
add_customer();
}
else if(num3)
{
add_sale();
}
else if(num4)
{
binary();
}
else
{
printf("Could not find match\n");
}
fclose(fp);

return 0;
}

void search(void)
{
FILE *fpcust;
int i, len_string;
char searchID [30];
char temp[30];

printf("What do you want to search for? \n");
scanf(" %s", searchID);

fpcust = fopen ("c:\\presdatatest.txt", "r");
rewind(fpcust);

if ( fpcust == NULL)
{
printf("File cound not be opened.");
exit(0);
}

else
{
len_string = strlen(searchID);

while (!feof ( fpcust ) )
{
for (i = 0; i < len_string; i++)
{
temp[i] = fgetc ( fpcust );
}
temp[i] = '\0';

//strcmp used for comparing both strings
if ( strcmp ( searchID, temp ) == 0)
{
printf("The ID was found \n");
fclose( fpcust);
system ("PAUSE");
exit(1);
}

else
{
printf("No matches found. \n");
system ("PAUSE");
exit (1);
}

fseek ( fpcust, - (len_string - 1), 1);
}
fclose ( fpcust );
}

}

void binary (void)
{

//creating biary copy of text file for customers
FILE *fpcust, *fpcustbin;
char buffer;
int ch;
int ch1;


//pointers pointing to files on the computer
fpcust = fopen("c:\\customers.txt", "r");
fpcustbin = fopen("c:\\customers.bin", "wb");


//creating binary copy of text file for customers
while ( ( ch = fgetc ( fpcust ) ) != EOF )
{
fread(&buffer, 1, 1, fpcust);
fwrite(&buffer, 1, 1, fpcustbin);
}


//closing the customer files
fclose(fpcust);
fclose(fpcustbin);


//creating binary copy of text file for sales
FILE *fpsales, *fpsalesbin;
char buffer1;


//pointers pointing to files on the computer
fpsales = fopen("c:\\sales.txt", "r");
fpsalesbin = fopen("c:\\sales.bin", "wb");


//copying text from sales text file into binary file
while ( ( ch1 = fgetc ( fpsales ) ) != EOF )
{
fread(&buffer1, 1, 1, fpsales);
fwrite(&buffer1, 1, 1, fpsalesbin);
}


//cosing the sales files
fclose(fpsales);
fclose(fpsalesbin);

}//end to binary function

void add_customer(void)
{

}

void add_sale(void)
{

}
[CODE]
Topic archived. No new replies allowed.