checking if entered a char
hello!
Well I must write a program that recieves 3 arguments and then returns if those 3 arguments make for a triangle (Equilateral triangle, Isosceles triangle and Scalene). For such the program must recieve only integers but we have to use this sentence: const char* Triang(int argc, char *argv[]) { ... } so the user can enter text as the second argument... The idea behind is that we learn how to differ from a char/string and an integer... however i do not know how to accomplish this... I know how to find out which type of triangle it is but not how to know if the user entered a letter or a string (say 'apple', '/', etc). Thanks for the time =D |
/* returns 0 if not integer 1 if integer */
int is_input_integer(char *input) { while (*input) { if (!isdigit(*input++)) return 0; } return 1; } call it like is_input_integer(argv[i]) |
or you could use this:
int a, b, c, d, e, f; if (1 == sscanf (argv[1], "%d", &a)) /*first number was an int*/; if (1 == sscanf (argv[2], "%d", &b)) /*second too*/ if (1 == sscanf (argv[3], "%d", &c)) ... ... if (1 == sscanf (argv[6], "%d", &f)) /*Houston, we have a triangle*/ a `cleaner' design would be to use a struct point { int x, y; }; Hope this helps, Jonas Kölker |
Thank you both very much!!
your help has been of great use! :D |
All times are GMT -5. The time now is 04:05 AM. |