- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
AI, Data Science, & Programming for Small Business Applications & Large Enterprises › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1: [C] – Data Types, Operators, Conditional Statements, Loops, and Command Line › Difference between scanf and get_int
Tagged: cs50 library, cs50.h, get_int, scanf
Suppose I want a user to enter an integer between 1 and 8.
To start with, here is the program that uses scanf to accept integer from user.
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include <stdio.h> #include <cs50.h> int main (void) { int number; printf ("enter a number "); scanf ("%i", &number); printf ("the number entered is %i", number); }
[/dm_code_snippet]
Gradually, I am to let the user enter integer between 1 and 8. If anything else is entered, the cursor will wait till the user enters integer between 1 and 8 (Mario World 1-1). The Hints apparenty prescribes to use get_int.
My query is if a similar objective cannot be by scanf. What is the difference between scanf and get_int? Is get_int better, more powerful?
Reply
https://cs50.stackexchange.com/questions/41814/difference-between-scanf-and-get-int[learn_press_profile]