5
I’m doing a show that reads a string and want to ignore the spaces and letters that the user type (but I have to read the letters i and p and the mathematical symbols +-/*^).
What I have achieved so far is to ignore only spaces. I thought that instead of ignoring what I do not want, I accept only what I want. So I need to know how to compare with an interval.
#include <stdio.h>
#include <stdlib.h>
void main()
{
char t[10];
char r[10];
fgets(t, 10, stdin);
int i = 0;
int c = 0;
for (i=0; i<10; i++){
if (t[i] !=' '){
r[c]=t[i];
c++;
}
}
printf("%s", r);
}
I did it separately without using isdigit (I didn’t understand what it’s for) and it worked, but when printing the vector on the screen always print a P0 at the end. You know why this happened?
– Miguel Goffredo
No, I don’t know what you did.
– Maniero
The isdigit is used to check if the character passed is a digit (i.e., if it is between 0 and 9).
– Tiago Martins
isdigit
in some implementations is a query to a hash table. This allows the operation to be performed in a command.– Jefferson Quesado