/*
This program is to input wizard detail into disk, display all the wizard details and search for particular wizard detail using wizardID or name. How to solve my problem as stated below?
My display function also cannot work... PLEASE help to solve my problem.
*/
/**************************************************/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define false 0
#define true 1
void add();
void display();
void search();
void remove();
FILE *MyFile;
int bytesWritten;
int bytesRead;
char wanted[10]; //If this is int, then my file input and output
char found; // is working correctly.
struct WizardStructure
{
char Name[30], Magic[100];
char WizardID[10]; //If this is int, then my file input and
}Wizard; //output is working correctly.
/************************************************** */
void main()
{
}
/************************************************** */
void add()
{
MyFile = fopen("Wizard.dat", "r+b");
if (!MyFile)
MyFile = fopen("Wizard.dat", "w+b");
printf("\n Enter Wizard name : ");
scanf(" %[^\n]", Wizard.Name);
printf("\n Enter Wizard ID : ");
scanf(" %]^\n]", Wizard.WizardID); //question as above
printf("\n Enter MAGIC POWER of the Wizard : ");
scanf(" %[^\n]", Wizard.Magic);
fseek (MyFile, 0, SEEK_END);
bytesWritten = fwrite((void*)&Wizard, sizeof(Wizard), 1, MyFile);
fclose (MyFile);
}
/************************************************** */
void display()
{
fprintf(stdout, "\n Wizard Name\t\t Wizard ID\t\t Wizard Magic");
fprintf(stdout, "\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~");
FILE *MyFile;
MyFile = fopen ("Wizard", "r+b");
if (fseek (MyFile, 0, SEEK_SET) == 0 );
{
bytesRead = fread ((void*) & Wizard, 1, sizeof(Wizard), MyFile);
while ( !feof (MyFile))
{
fprintf(stdout, "\n %s\t\t\t %s\t\t\t %s", Wizard.Name, Wizard.WizardID, Wizard.Magic);
bytesRead = fread ((void*) & Wizard, 1, sizeof(Wizard), MyFile);
}
}
}
/************************************************** */
void search()
{
MyFile = fopen ("Wizard.dat", "r+b");
printf("\n Enter Wizard's ID : ");
gets (wanted);
fseek (MyFile, 0, SEEK_SET);
found = false;
while (( !feof (MyFile)) && (found != true))
{
bytesRead = fread ((void*) & MyFile, sizeof (MyFile), 1, MyFile);
if (bytesRead > 0)
if ("Wanted" == "Wizard.WizardID") //question as
found = true; //above
}
if (found == true)
{
printf("\n WizardID : %s", Wizard.WizardID);
printf("\n Name : %s", Wizard.Name);
printf("\n Wizard's Magic : %s", Wizard.Magic);
}
else
printf("\n WizardID is not found");
fclose(MyFile);
}