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 8594651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:14:51+00:00 2026-06-12T00:14:51+00:00

I did part of this code for a class exercise and the code is

  • 0

I did part of this code for a class exercise and the code is working but i do not really understand what is happening in a particular piece.

Can anyone please explain this part:

if(scanf("%d%c", &num1, &term1) != 2 || term1 != '\n'){

    printf("ERROR! You should type an integer e.g 5, 80, 100\n");

} else { ....

The complete code is :

#include <stdio.h>

int main(){

int num1,num2;

char term1,term2;

printf("Type your first integer\n");

if(scanf("%d%c", &num1, &term1) != 2 || term1 != '\n'){

    printf("ERROR! You should type an integer e.g 5, 80, 100\n");

} else {

    printf("Type your second integer\n");

    if (scanf("%d%c", &num2, &term2) != 2 || term1 != '\n'){

        printf("ERROR! You should type an integer e.g 5, 80, 100\n");

    } 

    printf("\n%d", num1);
    for (int i=0; i<num1; i++) {
        printf(" *");
    }

    printf("\n");

    printf("%d", num2);
    for (int j=0; j<num2; j++) {
        printf(" *");
    }
}
}

The exercise was to make a program requesting 2 integers values and making a horizontal bar graph with the two values.

Thanks.

  • 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-12T00:14:52+00:00Added an answer on June 12, 2026 at 12:14 am

    scanf() returns the number of terms it successfully received. You’re asking for two terms, so you’re comparing the result to ensure both were received. You’re then checking the character term to ensure it was a carriage return, so you know the user did not type any other text after entering the numeric term.

    I strongly agree with @Vlad’s comment about reading the documentation. If you post for help on questions that can be resolved yourself without any real effort, you’re doomed when you get exposed to more complicated things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run this tutorial i did not implement the validation part
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
I did see this piece of code in a book and provoked my few
I know this code is correct, I did not write it. I am trying
Maybe I'm doing something really wrong, but somehow this code always crashes with a
We had a piece of code in C in one class where we needed
I wrote this hash map (this was a part of telephonic interview exercise), where
This question might be a bit sketchy because I do not have the code
The part of the cell that is orange, i did it with the storyboard,
Did you ever have the following situation: you need to store information, but a

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.