CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
Zone's C Programming Tutorials #3 Scanf function
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="ZoneAye" data-source="post: 14574" data-attributes="member: 18741"><p>Hi guys this is my third C Programming Tutorial in this tutorial we will be looking at the Scanf function. It is a very easy function to learn/use. It is used to allow the user to input data and then store the data. This is a example of code using Scanf <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /></p><p></p><p>int main()</p><p>{</p><p> // variable </p><p> int age; </p><p> // output to screen (question)</p><p> printf("Enter Age: "); </p><p> // storing input </p><p> scanf("%d", &age); </p><p> </p><p> // outputting answer </p><p> printf("You are %d years old", age); </p><p> fflush(stdin); </p><p> getchar();</p><p>}</p><p></p><p>As you can see when we are storing a integer using scanf we still use the character conversation %d this is because we storing a integer ovb. When u use Print and Scanf always use fflush(stdin); if you don't your program may not work. </p><p></p><p></p><p>All the code will do when you run it is output this on the console:</p><p>"Enter Age : 17 " <-- enter age </p><p>"You are 17 years old" <-- out puts entered age etc </p><p></p><p>You will not see the scanf or any other code in the console this is a quick brake down:</p><p>*runs code </p><p></p><p>Enter age: " <-- waits for u to enter age MUST be whole number</p><p>scanf <-- stores input </p><p>"You are (age) years old" <-- outputs age entered </p><p></p><p> you can use scanf for basically anything when inputting data i would recommend messing about with it and try to figure out why & is next to age in the scanf statement its very easy <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /> </p><p></p><p>- Zone</p></blockquote><p></p>
[QUOTE="ZoneAye, post: 14574, member: 18741"] Hi guys this is my third C Programming Tutorial in this tutorial we will be looking at the Scanf function. It is a very easy function to learn/use. It is used to allow the user to input data and then store the data. This is a example of code using Scanf :) int main() { // variable int age; // output to screen (question) printf("Enter Age: "); // storing input scanf("%d", &age); // outputting answer printf("You are %d years old", age); fflush(stdin); getchar(); } As you can see when we are storing a integer using scanf we still use the character conversation %d this is because we storing a integer ovb. When u use Print and Scanf always use fflush(stdin); if you don't your program may not work. All the code will do when you run it is output this on the console: "Enter Age : 17 " <-- enter age "You are 17 years old" <-- out puts entered age etc You will not see the scanf or any other code in the console this is a quick brake down: *runs code Enter age: " <-- waits for u to enter age MUST be whole number scanf <-- stores input "You are (age) years old" <-- outputs age entered you can use scanf for basically anything when inputting data i would recommend messing about with it and try to figure out why & is next to age in the scanf statement its very easy :) - Zone [/QUOTE]
Verification
Post reply
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
Zone's C Programming Tutorials #3 Scanf function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top