• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hanging
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hanging


  • Subject: Re: Hanging
  • From: David Rogers <email@hidden>
  • Date: Wed, 5 Jul 2006 21:11:44 -0500

I would check the value of i there, I would bet that you're trying to read past the bounds of the array and that's why it's crashing.

Changing the <= to < will most likely fix the problem.

for ( i=0; i < 1; i++)

Hope that helps,

Dave Rogers

On Jul 5, 2006, at 7: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:
40mac.com


This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

  • Follow-Ups:
    • Re: Hanging
      • From: Michael <email@hidden>
References: 
 >Hanging (From: Michael <email@hidden>)

  • Prev by Date: Re: XCode Dock Icon
  • Next by Date: Re: Hanging
  • Previous by thread: Hanging
  • Next by thread: Re: Hanging
  • Index(es):
    • Date
    • Thread