can someone explain something to me please help quickly

ok i am needing to build a program that searches a clients.dat folder and pulls up a a last name, first name and then an option to search for groups of measuments

here is the main program that writes to and updates clients.dat and im also having trouble getting this to run together

#include <stdio.h>
struct clientData {
char lastname[30];
char firstname[30];
char email[30];
};

void read( FILE *cfPtr);
void write( FILE *cfPtr);
void update( FILE *cfPtr);

int main( void )
{
FILE *cfPtr;
int result;

struct clientData client = { "", "", "" };

if ( ( cfPtr = fopen( "credit.dat", "rb" ) ) == NULL ) {
puts( "File could not be opened." );
}
else {
printf( "%29s%29s%29s\n", "Last Name", "First Name", "Email" );

while ( !feof( cfPtr ) ) { result = fread( &client, sizeof( struct clientData ), 1, cfPtr );

if ( result != 0 && client.lastname != 0 ) {
printf( "%-16s%-16s%-16s\n", client.lastname, client.firstname, client.email );
}
}

fclose( cfPtr );
}

}

int write(void)
{
char lastname[30];
char firstname[30];
char email[30];

FILE *cfPtr;

if ((cfPtr = fopen("clients.dat", "w")) == NULL){
puts("File could not be opened");
}
else{
puts("Enter the Last name, First name, and Email.");
puts("Enter EOF to end input.");
printf("%s", "?");
scanf("%29s%29s%29s", lastname, firstname, email );

while (!feof(stdin)){
fprintf(cfPtr, "%s\n" "%s\n" "%s\n", lastname, firstname, email );
printf("%s", "? ");
scanf("%29s%29s%29s", lastname, firstname, email );
}

fclose(cfPtr);
}
return 0;
}

int update(void)
{
char lastname[30];
char firstname[30];
char email[30];

FILE *cfPtr;

if ((cfPtr = fopen("clients.dat", "r+")) == NULL){
puts("File could not be opened");
}
else{
puts("Enter the Last name, First name, and Email.");
puts("Enter EOF to end input.");
printf("%s", "? ");
scanf("%29s%29s%29s", lastname, firstname, email );

while (!feof(stdin)){
fprintf(cfPtr, "%s\n" "%s\n" "%s\n", lastname, firstname, email );
printf("%s", "? ");
scanf("%29s%29s%29s", lastname, firstname, email );
}

fclose(cfPtr);
}
return 0;
}

here is the measurments program that needs to be my sub option to search for groups of measuments

#include <stdio.h>
#include <string.h>

struct clientData {
unsigned int acctNum;
char lastName[ 15 ];
char firstName[ 10 ];
double balance;
};

int main (void)
{

unsigned int i;

struct clientData blankClient = { 0, "", "", 0.0 };

FILE *cfPtr;

if ( ( cfPtr = fopen( "client.dat", "wb" ) ) == NULL ) {
puts( "file could not be opened." );
}
else{
for ( i = 1; i <= 100; ++i ) {
fwrite( &blankClient, sizeof( struct clientData ), 1, cfPtr );
}

fclose ( cfPtr );
}


char *Items[] = {"\nBust", "\nWaist", "\nHips", "\nBack Width", "\nFront Chest", "\nShoulder", "\nNeck Size", "\nSleeve", "\nUnder Bust", "\nWrist", "\nUpper Arm", "\nCalf", "\nAnkle", "\nNape To Waist", "\nWaist To Hip", "\nFront Shoulder To Waist", "\nOutside Leg", "\nInside Leg" };
int sizes[] = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,0.00, 0.00, 0.00, 0.00, 0.00, 0.00 };
char askthem[] = {"Please enter the appropriate values in inches for each item"};
char tellthem[] = {"here is what you put"};
char *erorfound = {"You have entered a value that is inappropriate"};

printf("%s", askthem);
for (int i = 0; i < 18; ++i)
{
printf("%s : ", Items[i]);
scanf("%f", &sizes[i]);
}


}
try the <> button on the right side of the reply/edit menu or
[code][/code]

And what exactly is the "trouble" you are having?

Oh and try to indent also so it is more readable.
Last edited on
Topic archived. No new replies allowed.