Alex Rivera | Logout

What is the easiest way to get an int in a console app?

Asked 2009-05-14T19:42:01.540
14

I want to process user input as an integer, but it seems as though C has no way to get an int from stdin. Is there a function to do this? How would I go about getting an int from the user?

Edit
Report

1 Answer

25
#include <stdio.h>

int n;
scanf ("%d",&n);

See http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

answered 2009-05-14T19:44:32.500

Your Answer