I am writing a simple code in c to extract the values from string for ex-P23V32 gives me output of 23*32. But when I am trying to use the isalpha() and isdigit() to check whether the value is a charecter or a digit, the compiler return always zero. Here is my code.

main ()
        /*Declaring variables*/
        int k=0;
        int input[25];
        int n=0,point=0;

        /*Getting input from the user*/
        printf("Enter the Formula\n");
        while(input[k]=getchar() != '\n')

        n=k;//copying the size of the input variable to the variable n

                int s = isalpha(input[point]);
                printf("The value of ss is %d",s);

I am new to C. Please help me out

> while(input[k]=getchar() != '\n')

You wrote
while(input[k]=(getchar() != '\n'))
which just assigns boolean 0 or 1 based on the logical test.

You want
while( (input[k]=getchar()) != '\n')
which assigns the character read to the array, then compares it.

But... the compiler return always zero.

the compiler is not returning zero. the compiler is what builds your code into a binary executable after linking the appropriate functions from teh standard libraries. the binary (program) is thing that, during runtime, returns your values of zero or otherwise.

so, you know, I'm just sayin'.

otherwise ... what Salem says ^


This question has already been answered. Start a new discussion instead.