I'm using the Turbo C 2.01 compiler for this example that I copied from the book "Hands - on Turbo C" by Larry Joel Goldstein and Larry Gritz. It won't compile because of this line:
if Entry.Name = SearchName then
I tried fix the error myself, but I don't know how to convert the above line to C. It looks like qbasic to me.
Code:
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <sys\stat.h>
typedef struct {
char Name[20];
char Number[12];
} PhoneNum;
int Directory;
int accessmode;
PhoneNum Entry;
char SearchName[20];
int Found;
main()
{ /* PhoneSearch */
printf("Whose phone number to search for? ");
gets (SearchName);
accessmode = O_RDONLY | O_BINARY;
Directory = open("PHONE", accessmode);
Found = 0;
while(!Found && !eof(Directory))
if (!strcmp(SearchName,Entry.Name))
/* if Entry.Name = SearchName then */
Found = 1;
else
read(Directory,&Entry,sizeof(Entry));
close(Directory);
if(Found)
printf("Successful: %s", Entry.Number);
else
printf("Unsucessful\n");
} /* PhoneSearch */