[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Stupid C code..



Hi Shridhar,

Before posting code, please ensure that it at least compiles without a single
error with gcc -Wall. That would help others in looking through the code.

Shridhar Daithankar forced the electrons to say:
> main() {
>  printf("\nEnter a string.. ");
>  gets(a);

Use fgets() here. gets() will get you into more trouble than you bargained
for.

>  line=a;
>   if(line[0]!=32||line[0]!=9)  /*Line has no initial white spaces*/

What is wrong with #include <ctype.h> and then, if (!isspace (*line))?

>   {
>    ftemp++;
>    while(line[i]!=0||line[i]!=32||line[i]!=9){printf(" %d",line[i]);i++;}

Are you sure the condition for that while is correct? Because, if that is the
case, then you have an infinite loop here. When *line is a null byte, the first
condition evaluates to false, but the next one evaluates to true. If *line is
not a null byte, the first itself will evaluate to true. So, in any case, the
test in the while returns true, irrespective of *line's value.

It is this infinite loop that makes your code dump core.

Binand

-- 
The prompt for all occasions:
export PS1="F:\$(pwd | tr '/[a-z]' '\134\134[A-Z]')> "
--------------- Binand Raj S. (binand@xxxxxxxxxxxxxxxxxxxxx)