How to recognize the data type entered - C [closed]

-2

I'm doing a program where the user can register, fetch and remove clients. To enter it type "insert [client name]" and a code is generated automatically. I have a problem with the search function. Currently the user has to type: "find x y" where x is an int q identifies whether the search will be done by the code or customer name and y is the corresponding value. I wanted to do this without asking the user to specify the type of search. Is there a way to get the data and then check if I got an integer or a string?

    
asked by anonymous 17.07.2017 / 12:50

1 answer

0

You can use the isdigit function, you have to go through the whole input with it, if you put the code is easier, but here is an example taken from watcom c help.

#include <stdio.h>
#include <ctype.h>

    //Aqui você não necessita por um vetor, imagine que seja o texto que 
     você está armazenando

char chars[] = {
    'A',
    '5',
    '$'
};
#define SIZE sizeof( chars ) / sizeof( char )
int main()
{
    int   i;

    //Faça um for percorrendo a entrada caracter por caracter

    for( i = 0; i < SIZE; i++ ) {
        printf( "Char %c is %sa digit character\n",
                chars[i],
                ( isdigit( chars[i] ) ) ? "" : "not " );
                 //Verifique na função isdigit se é um numero ou não, da 
proxima vez por favor deixar o codigo
    }

    return 0;
}
    
17.07.2017 / 13:25