isspace and ternery problem

Small example code to show the problem.

#include <stdio.h>

#include <stdio.h>

#include <ctype.h>

#include <strings.h>


int main (int argc,char *argv[]) {


printf("enter a sentence: ");


char c;


while((c=getchar())!=EOF){

        if(isspace(c)) continue;

        else putchar(c);
}

   return(0);

}

compiles runs as expected.

now I wanna switch the block to ternery

while((c=getchar())!=EOF) isspace(c)?continue:putchar(c);

error when compiling: F:\tests\main.c|12|error: expected expression before ‘continue’|

isspace is returning int either 0 or integer…I cant get why everything works without ternery and gives this error with ternery.

thanks.

The ternary operator is used to calculate a value from two expressions based on the value of a third. continue is not an expression so you can't use it like that.

In C and C++ conditional expressions are written:
? :

as in

int larger (int a, int b)
{
  return a > b ? a : b ;
}

If you have

if (isspace(c))
    continue;
  else
    putchar(c);

you can drop the else, the continue behaves like a goto.

if (isspace(c)) {
    continue;
  }
  putchar(c);

Or for your example

while ((c=getchar())!=EOF) {
  if(!isspace(c))
    putchar(c);
}

Thanks guys...

@wildbill yes the problem was because of continue.