Mail Archives: djgpp/2000/03/26/09:20:43
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 -