Re: Hanging
Re: Hanging
- Subject: Re: Hanging
- From: Dan White <email@hidden>
- Date: Wed, 5 Jul 2006 23:13:01 -0400
I am guessing you are in section 4.3, but I cannot tell which exercise
you are attempting.
Also, which edition of K&R are you using ? First Edition or Second
(ANSI C) Edition ?
On Jul 5, 2006, at 8:11 PM, Michael wrote:
Could I ask someone to run this little program. It is an attempt to
complete an exercise in K&R...but here is the problem.
Under Xcode it compiles ok...but when I step through it, it hangs
where I have indicated. It would really be nice if someone else could
replicate this and help me understand what the issue is. The code
itself does is really a "dummy" run for a later exercise.
thanks in advance:
X-code 2.3
Compiled with the Standard Tool.
>>>>>>
# include <stdio.h>
# include <string.h>
# define MAXNUM 10
# define TESTCHAR 'T'
int getops(char s[]);
int main (){
char s[MAXNUM], type;
while ( (type=getops(s)) != EOF){
switch (type) {
case 'T':
printf("%s\n", s);
break;
}
}
return 0;
}
/*****GETOPS******/
int getch(void);
void ungetch(int c);
int getops(char s[]){
int c, i;
while ( (c = getch()) == ' ' || c =='\t');
for ( i=0; i <= 1; i++) /*****HANGS HERE***/
ungetch('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++);
}
/******
Output("p" entered):
>>/beginning of output/<<
p
Printing line 1
Printing line 2
Printing line 3
Printing line 4
>>/end of output/<<
**/_______________________________________________
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
_______________________________________________
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
References: | |
| >Hanging (From: Michael <email@hidden>) |