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.

#include<stdio.h>
#include<ctype.h>
//#include<string.h>
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')
                k++;

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

        while(point<=(n-1))
                {
                int s = isalpha(input[point]);
                printf("The value of ss is %d",s);
                point++;
                }
        }

I am new to C. Please help me out

Recommended Answers

All 2 Replies

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

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 ^


.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.