Strange Behavior?

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Thu May 9 19:23:33 AEST 1991


In article <1991May8.020720.20170 at mccc.edu>, pjh at mccc.edu (Peter J. Holsberg) writes:
> Here is an extract from a program a student wrote.

Holsberg pointed out that a variable was declared char rather than int.
In that program, on a little-endian machine, it will work; making the
behaviour of longer and shorter integers consistent is what little-endian
is _for_, after all.

> #define MAX 9

>    char sentence [MAX][SIZE];   /* an array of strings */

>    printf("Input up to ten sentences \n");

There is a contradiction here.  If sentence[] is to hold up to 10
sentences, MAX had better be 10, not 9!

The input loop would be better as
	#define MAX 10
	for (num = 0;
	     num < 10 && gets(sentence[num]) != NULL
		      && strcmp(sentence[num], "") != 0;
	     num++)
	    point[num] = original[num] = sentence[num];

Note: gets() has problems.  Best to avoid it.  See the FAQ.
-- 
Bad things happen periodically, and they're going to happen to somebody.
Why not you?					-- John Allen Paulos.



More information about the Comp.lang.c mailing list