cvs.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000114

When Created: 10/13/1996 19:26:04
Against DJGPP version: 2.00
By whom: pdp10@sover.net
Abstract: 'for' or perhaps command line problem...
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.

Note added: 10/14/1996 13:45:40
By whom: stringer@munch.chem.washington.edu
I think your problem resides in the fact that the shell program you are
using is confusing the * on the command line for a wild card. In doing 
so it is passing a directory listing to your program in place of the *.
Try the following with your code.

rept "*" 10

This should behave in the proper manner. It does work properly if you do
not use any special charaters when running the code. such as the following.

rept a 10

Good luck. 

Closed on 04/13/1999 08:00:17: Usage error, not a bug.
By whom: eliz@is.elta.co.il



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