Re: Hanging
Re: Hanging
- Subject: Re: Hanging
- From: Rush Manbert <email@hidden>
- Date: Thu, 06 Jul 2006 17:42:52 -0700
Michael wrote:
On Jul 5, 2006, at 8:13 PM, Dan White wrote:
I am guessing you are in section 4.3, but I cannot tell which
exercise you are attempting.
Good guess...actually I am working on Exercises 4-6, 4-7.
I am using K&R 2;
This has really stumped me.
Michael,
I took your code and made a project from it. The only change is that I
put it all in one file and changed the function definition order. This
does not hang for me. As near as I can tell, it works as expected. I'm
pasting the contents of my main.c. Maybe you want to try it?
Oh, one other change. There is a warning with your original code about
getops reaching the end of a non-void function without returning
anything. I added the line that returns c, but I also tested it without
the added line and it didn't hang then either.
- Rush
# include <stdio.h>
# include <string.h>
# define MAXNUM 10
# define TESTCHAR 'T'
/***** GETCH & UNGETCH*****/
# define MAXBUFF 10
char buffer[MAXBUFF];
int buffp=0;
int j=1;
int getch(void){
return (buffp > 0) ? buffer[--buffp]: getchar() ;
}
void ungetch(int c){
printf("Printing line %d\n", j++);
}
/*****GETOPS******/
int getops(char s[]){
int c, i;
while ( (c = getch()) == ' ' || c =='\t');
for ( i=0; i <= 1; i++) /*****HANGS HERE***/
ungetch('T');
return c;
}
int main (){
char s[MAXNUM], type;
while ( (type=getops(s)) != EOF){
switch (type) {
case 'T':
printf("%s\n", s);
break;
}
}
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden