UMBC CS 201, Spring 02
UMBC CMSC 201 Spring '02 CSEE | 201 | 201 S'02 | lectures | news | help

scanf

Our first program using scanf simply reads in an integer and a double and prints them out.

The Program

/********************************************* ** File: scanf.c ** Author: S. Bogar ** Date: 8/25/99 ** Section: 101 ** SSN: 123-45-6789 ** EMail: bogar@cs.umbc.edu ** ** This program demonstrates the use ** of the scanf function. **********************************************/ #include <stdio.h> int main ( ) { int n ; double x ; printf("Enter an integer: ") ; scanf("%d", &n) ; printf("Enter a double: ") ; scanf("%lf", &x) ; printf("n = %d, x = %f\n", n, x) ; return 0; }

The Sample Run

linux3[84] % a.out Enter an integer: 34 Enter a double: 342.123 n = 34, x = 342.123000 linux3[85] % !a a.out Enter an integer: 34 Enter a double: 34e12 n = 34, x = 34000000000000.000000 linux3[86] % !a a.out Enter an integer: 34e12 Enter a double: n = 34, x = 0.000000 linux3[87] % !a a.out Enter an integer: bbb bbb Enter a double: n = 134518044, x = 0.000000 linux3[88] %


CSEE | 201 | 201 S'02 | lectures | news | help

Thursday, 17-Jan-2002 13:52:24 EST