`

Inline Code Example Here



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

struct contact_detail
{
int id;
char user_name[15];
char email_address[15];
int phone_number[10];
char address[10];
};

struct meeting/appointment
{
    int date_of_meeting/appointment[7];
    int time_of_meeting/appointment[4];
    char location[15];
};

struct  new_user;
struct meeting;

void add_new_record(void);
void binary(void);
void delete_record(void);
void edit_record(void);
void search_record(void);
main()
{
FILE* fp;

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

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

int num1, num2, num3, num4;

printf("Please enter\n1. to add a new record \n2. to delete a record\n3. to edit a record\n4. search record\n");
scanf("%5d", &num1, &num2, &num3, &num4);

if(num1)
{
add_new_record();
}
else if(num2)
{
delete_record();
}
else if(num3)
{
edit_record();
}
else if(num4)
{
search_record();
}
else
{
printf("Could not find match\n");
}
fclose(fp);

return 0;
}

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

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

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

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

else
{
len_string = strlen(searchID);

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

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

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

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

}

void binary (void)
{

//creating biary copy of text file for user
FILE *fpuser, *fpuserbin;
char buffer;
int ch;
int ch1;


//pointers pointing to files on the computer
fpuser = fopen("c:\\users.txt", "r");
fpuserbin = fopen("c:\\users.bin", "wb");


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


//closing the user files
fclose(fpuser);
fclose(fpuserbin);


//creating binary copy of text file for meeting
FILE *fpmeeting, *fpmeeting;
char buffer1;


//pointers pointing to files on the computer
fpuser = fopen("c:\\meeting.txt", "r");
fpuserbin = fopen("c:\\meeting.bin", "wb");


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


//cosing the meeting files
fclose(fpmeeting);
fclose(fpmeetingbin);

}//end to binary function

void add_new_record(void)
{

}

void delete_record(void)
{

}
void edit_record(void)
{

}
void search_record()
{

}

`

So why did you post all that code?

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.