B
bpascal123
Hi,
I am first an accountant and decided to take on programming a few
years ago...
I have been first studying simple algorithms...
Now I have decided to first learn C (i'll give it 600 effective hours -
so btw 1 and 3 years) before going to c++ or perl, or python, java or
php or ruby on rails or vba, i'll see at that time what answers most
my needs either as a professionnal accountant or as a personal project
i'd like to take on... Is there anything specific I could do with a
good knowledge of C only ?
So I have been having a hard time with the basics of pointers (20
hours). I really want to feel ok with this before getting any further.
I haven't looked at functions yet.
Here is a programm I know by heart - from a book - but in this code it
doesn't work althought it is very similar to other versions I have
been "coding" over and over more than 30 times ... and 10 % of the
time, there is a bug very similar to the one below I can solve by
looking carefully at the code or cannot solve if I have looked
carefully at the code. That's why I'd like to learn how to debug.
So far or so early with learning C, I'd like to use this opportunity
to learn how to debug and know about the tools that can help.
I have mainly been programming under Windows Xp DJGPP Dolorie... and I
have found a command : simify (link : http://www.delorie.com/djgpp/v2faq/faq9_3.html
) to help debug.
===O===
FIRST, here is the culprit : (this prg inserts a symbol every 3 digits
if the number includes 4 or more digits)
===O===
#include <stdio.h> /* printf, putchar, gets, puts */
#include <conio.h> /* getche */
#include <stdlib.h> /* atoi */
#include <ctype.h> /* isdigit */
#include <string.h> /* strcpy, strlen */
#define BOOL int
/**********/
main()
{
char buffer[128] ;
char clearbuf[128] ;
char output[172] ;
char * pb = buffer, * pc = clearbuf, * po = output ;
int symbol ;
int i, k ;
int cnt ;
BOOL ok ;
/**********/
printf("\033[2J");
printf("\nCe prog separe...\n");
/**********/
do
{
printf("\nSeparateur :");
symbol = getche() ;
if ( symbol < 32 )
printf("Pas de caractere de control comme separateur !");
if ( isdigit(symbol) )
printf("Pas de chiffre comme separateur !" ) ;
} while ( symbol < 32 || isdigit(symbol) ) ;
/**********/
do
{
ok = 1 ;
printf("\nEntrez un nombre entier positif ");
gets(buffer) ;
cnt = 0 ;
while ( *(buffer + cnt) && ok )
{
if ( !isdigit(*(buffer + cnt) ) )
{
printf("Pas d'entier positif!") ;
ok = 0 ;
}
cnt++;
}
} while ( !ok ) ;
/**********/
if ( cnt > 1 && atoi(buffer) )
{
while ( *pb == '0' )
pb++ ;
while ( *pc++ = *pb++ )
;
strcpy(buffer, clearbuf);
}
/**********/
if ( (cnt = strlen(buffer)) > 3)
{
for ( i = cnt - 1, k = 0, pb = buffer ; i >= 0 ; i--, k++ )
{
po[k] = pb ;
if ( ( (cnt - i) % 3 ) == 0 && i != 0 )
po[++k] = symbol ;
}
po[k] = '\0' ;
for ( i = k - 1 ; i >= 0 ; i-- )
putchar(*(output + i));
}
else
puts(buffer) ;
}
===O===
Running this doesn't work after entering a symbol
NOW the simify cmd says (in an dmp output text file) :
===O===
Entrez un separateur : ;
Entrer un nbr (pas plus de 50 chiffres svp) 434334
Exiting due to signal SIGSEGV
General Protection Fault at eip=00001f9e
eax=00092ca5 ebx=0000029d ecx=0000000d edx=00000001 esi=00000054
edi=00012d74
ebp=00092d48 esp=00092b60 program=C:\DJGPP\ACT43B\PTRS36.EXE
cs: sel=01a7 base=029d0000 limit=0009ffff
ds: sel=01af base=029d0000 limit=0009ffff
es: sel=01af base=029d0000 limit=0009ffff
fs: sel=017f base=0000f860 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=029d0000 limit=0009ffff
App stack: [00092d74..00012d74] Exceptn stack: [00012cd4..00010d94]
Call frame traceback EIPs:
0x00001f9e _main+243
0x00003a38 ___crt1_startup+176
C:\DJGPP\act43b>symify ptrs36.exe
C:\DJGPP\act43b>symify -o ptrs36.exe
Invalid option -o - type `symify' for help
C:\DJGPP\act43b>symify -o pbb1.dmp ptrs36.exe
====O====
I don't know if I can use what simify says to find any bug.
=========
Am I using simify right ?
Is my bug tracable ?
What(free) tool in my windows Xp context can I use to debug ?
=========
Thanks in advance ,
Pascal
I am first an accountant and decided to take on programming a few
years ago...
I have been first studying simple algorithms...
Now I have decided to first learn C (i'll give it 600 effective hours -
so btw 1 and 3 years) before going to c++ or perl, or python, java or
php or ruby on rails or vba, i'll see at that time what answers most
my needs either as a professionnal accountant or as a personal project
i'd like to take on... Is there anything specific I could do with a
good knowledge of C only ?
So I have been having a hard time with the basics of pointers (20
hours). I really want to feel ok with this before getting any further.
I haven't looked at functions yet.
Here is a programm I know by heart - from a book - but in this code it
doesn't work althought it is very similar to other versions I have
been "coding" over and over more than 30 times ... and 10 % of the
time, there is a bug very similar to the one below I can solve by
looking carefully at the code or cannot solve if I have looked
carefully at the code. That's why I'd like to learn how to debug.
So far or so early with learning C, I'd like to use this opportunity
to learn how to debug and know about the tools that can help.
I have mainly been programming under Windows Xp DJGPP Dolorie... and I
have found a command : simify (link : http://www.delorie.com/djgpp/v2faq/faq9_3.html
) to help debug.
===O===
FIRST, here is the culprit : (this prg inserts a symbol every 3 digits
if the number includes 4 or more digits)
===O===
#include <stdio.h> /* printf, putchar, gets, puts */
#include <conio.h> /* getche */
#include <stdlib.h> /* atoi */
#include <ctype.h> /* isdigit */
#include <string.h> /* strcpy, strlen */
#define BOOL int
/**********/
main()
{
char buffer[128] ;
char clearbuf[128] ;
char output[172] ;
char * pb = buffer, * pc = clearbuf, * po = output ;
int symbol ;
int i, k ;
int cnt ;
BOOL ok ;
/**********/
printf("\033[2J");
printf("\nCe prog separe...\n");
/**********/
do
{
printf("\nSeparateur :");
symbol = getche() ;
if ( symbol < 32 )
printf("Pas de caractere de control comme separateur !");
if ( isdigit(symbol) )
printf("Pas de chiffre comme separateur !" ) ;
} while ( symbol < 32 || isdigit(symbol) ) ;
/**********/
do
{
ok = 1 ;
printf("\nEntrez un nombre entier positif ");
gets(buffer) ;
cnt = 0 ;
while ( *(buffer + cnt) && ok )
{
if ( !isdigit(*(buffer + cnt) ) )
{
printf("Pas d'entier positif!") ;
ok = 0 ;
}
cnt++;
}
} while ( !ok ) ;
/**********/
if ( cnt > 1 && atoi(buffer) )
{
while ( *pb == '0' )
pb++ ;
while ( *pc++ = *pb++ )
;
strcpy(buffer, clearbuf);
}
/**********/
if ( (cnt = strlen(buffer)) > 3)
{
for ( i = cnt - 1, k = 0, pb = buffer ; i >= 0 ; i--, k++ )
{
po[k] = pb ;
if ( ( (cnt - i) % 3 ) == 0 && i != 0 )
po[++k] = symbol ;
}
po[k] = '\0' ;
for ( i = k - 1 ; i >= 0 ; i-- )
putchar(*(output + i));
}
else
puts(buffer) ;
}
===O===
Running this doesn't work after entering a symbol
NOW the simify cmd says (in an dmp output text file) :
===O===
Entrez un separateur : ;
Entrer un nbr (pas plus de 50 chiffres svp) 434334
Exiting due to signal SIGSEGV
General Protection Fault at eip=00001f9e
eax=00092ca5 ebx=0000029d ecx=0000000d edx=00000001 esi=00000054
edi=00012d74
ebp=00092d48 esp=00092b60 program=C:\DJGPP\ACT43B\PTRS36.EXE
cs: sel=01a7 base=029d0000 limit=0009ffff
ds: sel=01af base=029d0000 limit=0009ffff
es: sel=01af base=029d0000 limit=0009ffff
fs: sel=017f base=0000f860 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=029d0000 limit=0009ffff
App stack: [00092d74..00012d74] Exceptn stack: [00012cd4..00010d94]
Call frame traceback EIPs:
0x00001f9e _main+243
0x00003a38 ___crt1_startup+176
C:\DJGPP\act43b>symify ptrs36.exe
C:\DJGPP\act43b>symify -o ptrs36.exe
Invalid option -o - type `symify' for help
C:\DJGPP\act43b>symify -o pbb1.dmp ptrs36.exe
====O====
I don't know if I can use what simify says to find any bug.
=========
Am I using simify right ?
Is my bug tracable ?
What(free) tool in my windows Xp context can I use to debug ?
=========
Thanks in advance ,
Pascal