Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-06-2002, 05:11 PM   #1
Member (6 bit)
 
Join Date: Mar 2002
Posts: 32
getting this example to compile

I'm using the Turbo C 2.01 compiler for this example that I copied out of the book "Hands - on Turbo C" by Larry Joel Goldstein and Larry Gritz. It appears the example has a mistake in it and I need help solving it.

Code:
#include 
#include 
#include 
#include 
#include 

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 - original line where error occurrs */
			Found = 1;
		else
			read(Directory,&Entry,sizeof(Entry));
	close(Directory);
	if(Found)
		printf("Successful: %s", Entry.Number);
	else
		printf("Unsucessful\n");
} /* PhoneSearch */
sheep is offline   Reply With Quote
Old 04-08-2002, 12:08 PM   #2
Registered User
 
c-learner's Avatar
 
Join Date: Dec 2000
Location: where justice defined.
Posts: 174
where is the PhoneNum method?? did you included it??

Last edited by c-learner; 04-08-2002 at 12:10 PM.
c-learner is offline   Reply With Quote
Old 04-08-2002, 12:33 PM   #3
Member (12 bit)
 
Paul Victorey's Avatar
 
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
What does the compiler complain about (what's the error?)
__________________
Paul M. Victorey
------------------
I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk.
Paul Victorey is offline   Reply With Quote
Old 04-08-2002, 05:31 PM   #4
Member (6 bit)
 
Join Date: Mar 2002
Posts: 32
The compiler says:
If missing ( in function main
misplaced else in function main


My problem is with this line:
if Entry.Name = SearchName then

How do you translate that to C? The overall purpose of the program is to search through a file for a person's name and output their phone number.
sheep is offline   Reply With Quote
Old 04-08-2002, 06:53 PM   #5
Member (12 bit)
 
Paul Victorey's Avatar
 
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
The if line looks correct. You do need brackets around your while loop, though, that might be the problem.

If that doesn't work, I'll try compiling this myself later today, but I've got a paper to write first.
Paul Victorey is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:54 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2