Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-15-2005, 08:55 AM   #1
Registered: Aug 2003
Location: Sweden
Distribution: Ubuntu 10.04
Posts: 99

Rep: Reputation: Disabled
checking if entered a char

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
Old 03-15-2005, 09:40 AM   #2
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
/* 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

Last edited by zeropash; 03-15-2005 at 09:41 AM.
Old 03-15-2005, 12:58 PM   #3
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
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
Old 03-16-2005, 09:22 PM   #4
Registered: Aug 2003
Location: Sweden
Distribution: Ubuntu 10.04
Posts: 99

Original Poster
Rep: Reputation: Disabled
Thank you both very much!!
your help has been of great use!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C pointers confusion - char ** = char [][] ?? saravkrish Programming 12 12-02-2004 10:06 AM
C Problem---convert char to char* totti10 Programming 11 11-06-2004 11:32 AM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM
convert from char* to unsigned char* D J Linux - Software 2 02-20-2004 04:09 AM
Copy a char* to another char* sathyan Programming 8 07-24-2003 06:15 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration