String Conversions - int main() { double i, j;...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
3: Formatted I/O String Conversions To print characters and strings, the following conversions are used: c character s character string printf("%c", 'a'); printf("%d", 'a'); printf("This %s test", "is");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3: Formatted I/O More on scanf() scanf() returns the number of items that have been successfully read, and EOF if no items have been read and end-file has been encountered. For example returns the following value: 2 if both input operations were successful 1 if only the first input operations was successful 0 if the input operation failed EOF if an end-of-file has been encountered.
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int main() { double i, j; printf("Enter two double values:"); if(scanf("%lf%lf", &i, &j) != 2) return EXIT_FAILURE; printf("sum = %f\ndifference = %f\n", i + j, i - j); return EXIT_SUCCESS; } Idiom ? Example Read Single Integer with prompt printf("Enter integer: "); if(scanf("%d", &i) != 1 ) /* error, else OK */ Read Two Integers if(scanf("%d%d", &i, &j) != 2 ) /* error, else OK */ 3: sizeof C operator sizeof (type name) or sizeof expression returns the size of the data type or object represented by the...
View Full Document

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 5

String Conversions - int main() { double i, j;...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online