I am using RHIDE, and am a slightly new coder. I was recently coping a program directly from a tutoring C book. After I ran it, it didnt run as it said it should, and I am positive that it is in correctly. The Source is as follows:
#include <stdio.h>
#include <stdlib.h>
void main(int argc,char *argv[])
{
int x,r;
char c;
if(argc<3)
{
printf("Syntax:
rept <character> <# of repetitions>\n");
exit(0);
}
c=argv[1][0];
r=atoi(argv[2]);
for(x=0;x<r;x++)
putchar(c);
}
This program should run from the command line, with 2 arguments, a character, followed by a integer, such as:
rept * 10
It should then putchar(*) 10 times. It does not. When I used GDB, and stepped it through, the program jumped from
the for(x=0;x<r;x++) line directly to the ending parenthesis. It hopped right over the putchar() line.
The program goes from the for line to a line in another module... Here is a copy of my gdb session:
(gdb) break main
Breakpoint 1 at 0x1580: file rept.c, line 9.
(gdb) run * 10
Starting program: d:/temp/rept * 10
Breakpoint 1, main (argc=43, argv=0x52100) at rept.c:9
9 if(argc<3)
(gdb) step
15 c=argv[1][0];
(gdb) step
16 r=atoi(argv[2]);
(gdb) step
18 for(x=0;x<r;x++)
(gdb) step
20 } (gdb) step
0x1b03 in __crt1_startup ()
(gdb) step
Single stepping until exit from function __crt1_startup,
which has no line number information.
Program exited normally.
go32_close called
(gdb)
Like I said, the tutoring book I am using has the same exact source, and it is supposed to work fine... if it is just a personal error, PLEASE tell me what I did. Thanks alot.
Nick 'Drak' P.