Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:53:17+00:00 2026-06-12T20:53:17+00:00

I have a triangle program in c #include <stdio.h> // A function which decides

  • 0

I have a triangle program in c

#include <stdio.h>

// A function which decides the type of the triangle and prints it
void checkTriangle(int s1, int s2,int s3)
{
    // Check the values whether it is triangle or not.
    if ((s1 + s2 > s3 && s1 +  s3 > s2 && s2 + s3 > s1) && (s1 > 0 && s2 > 0 && s3 > 0))
    {
        // Deciding type of triangle according to given input.
        if (s1 == s2 && s2 == s3)
            printf("EQUILATERAL TRIANGLE");
        else if (s1 == s2 || s2 == s3 || s1 == s3)
            printf("ISOSCELES TRIANGLE\n");
        else
            printf("SCALENE TRIANGLE \n");
    }
    else
        printf("\nTriangle could not be formed.");
}

int main(void)
{
    // Initializing variables
    int a,b,c;

    // Getting input from user
    printf("Please enter the sides of triangle");

    printf("\nPlease enter side 1:");
    scanf("%d",&a);

    printf("Please enter side 2:");
    scanf("%d",&b);

    printf("Please enter side 3:");
    scanf("%d",&c);

    // Calling function in order to print type of the triangle.
    checkTriangle(a,b,c);
}

When the input is:

7b

it gives an error, which is what I want, but when I entered the data like this:

7
7
7b 

it ignores ‘b’ and take 7 as an integer — but why? How can I prevent this?

What I want to do is give an error also for

7
7
7b
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:53:18+00:00Added an answer on June 12, 2026 at 8:53 pm

    If you want to be able to detect an error with the user’s input, such as a line not being a valid decimal integer, then you could do the following:

    • Read the input into a buffer using fgets(buffer, size, stdin)
    • Use strtoul(buffer, &endptr, 10) to parse the buffer as a decimal integer (base 10), where endptr is a char*
    • endptr will point to the first invalid character in buffer, ie. the character after the last one which was successfully parsed
    • Now if *endptr == '\0', ie. endptr points to the end of buffer, the whole string was parsed as a valid decimal integer
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am creating a program to generate pascal's triangle, which I know has
I am attempting to learn C and I have written a small program which
I have designed a program which, basically, cuts a geometrical shape into many small
I have a simple openGL ES program which basically sets up two triangles which
In my program, I have a class called Object, which inherits from UIView. I
I have a program that draws a random triangle. I wanted to add a
I have a triangle in 3D space defined by its 3 vertices, p0, p1,
I have a triangle in (u,v) coordinates in an image. I would like to
i'm not sure how to solve the following problem: i have a triangle with
Here is my custom class that I have that represents a triangle. I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.