delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/26/09:20:43

Date: Sun, 26 Mar 2000 16:05:07 +0500
Message-Id: <200003261105.QAA03914@midpec.com>
From: tr AT midpec DOT com (Prashant TR)
To: djgpp AT delorie DOT com
In-reply-to: <20000325133610.00647.00003156@ng-cl1.aol.com> (ripter01@aol.com)
Subject: Re: Help Please
References: <20000325133610 DOT 00647 DOT 00003156 AT ng-cl1 DOT aol DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: dj-admin AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

ripter01 AT aol DOT com (Ripter01) proclaimed:

> From: ripter01 AT aol DOT com (Ripter01)
> Date: 25 Mar 2000 18:36:10 GMT
> DJ-Gateway: from newsgroup comp.os.msdos.djgpp
> 
> I have this strange (strange to me) problem with one of my C programs
> the frist time I run it It works just as I want it to, but anytime after that
> it prints a bunch of junk on the screen like:
> 
> Exiting to due to signal SIGSEGV
> General Production Fault at eip=00002ff3
> 
> and then a bunch of stuff that looks like Asm resters and stuff
> If I reboot, then I can run the program once without this happaning but then it
> happans again, i don't get it, Please help, Here is my code
> 
> /* Pad.c */
> 
> #include <stdio.h>
> #include <string.h>
> 
> main()
> {
>  char Text[20][81], CharTemp;
>  int Count,Counter,Temp, i;
> 
>  for( i = 0; i <=20; i++)
>   strcpy(Text[i], "");
> 
>  puts("This will \"pad\" your lines");
>  puts("Type quit on a newline to exit");
> 
>  do
>  {
>   Count++;
>   printf(">");
>   gets(Text[Count]);
>  } while( strcmp("quit",Text[Count]) != 0 );
> 
>  for( Counter = 0; Counter <= Count; Counter++ )
>   if( strlen(Text[Counter]) < 70)
>     for( Temp = strlen( Text[Counter] ); Temp <= 70; Temp++ )
>      strcat(Text[Counter],".");
> 
>  for( Counter = 0; Counter <= 20; Counter++ )
>   printf("\n%s",Text[Counter]);
> }
> 

There are lots of bugs. The corrected version...

/* Pad.c */

#include <stdio.h>
#include <string.h>

main()
{
 char Text[20][81], CharTemp;
 int Count,Counter,Temp, i;

 for( i = 0; i < 20; i++)//bug 1
  strcpy(Text[i], "");

 puts("This will \"pad\" your lines");
 puts("Type quit on a newline to exit");

 Count = -1; // Bug 2.

 do
 {
  Count++;
  printf(">");
  gets(Text[Count]);
 } while(( strcmp("quit",Text[Count]) != 0 ) && (Count < 20)); // Bug 3.

 for( Counter = 0; Counter < Count; Counter++ ) // Bug 4
  if( strlen(Text[Counter]) < 70)
    for( Temp = strlen( Text[Counter] ); Temp <= 70; Temp++ )
     strcat(Text[Counter],".");

 for( Counter = 0; Counter < 20; Counter++ ) // Bug 5.
  printf("\n%s",Text[Counter]);
}

Hope this does it.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019