1 / 11

INTERACTIVE OUTPUT FUNCTIONS

INTERACTIVE OUTPUT FUNCTIONS printf-The computer (i.e. the program) sends its processed output to the standard output device – monitor screen. other standard commands : sprintf, putchar, puts. FORMATTED INPUT & OUTPUT. INTERACTIVE OUTPUT FUNCTIONS

britain
Download Presentation

INTERACTIVE OUTPUT FUNCTIONS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INTERACTIVE OUTPUT FUNCTIONS printf-The computer (i.e. the program) sends its processed output to the standard output device – monitor screen. other standard commands:sprintf, putchar, puts.

  2. FORMATTED INPUT & OUTPUT INTERACTIVE OUTPUT FUNCTIONS printf-The computer (i.e. the program) sends its processed output to the standard output device – monitor screen. other standard commands:sprintf, putchar, puts.

  3. OUTPUT FUNCTION OF printf GENERAL SYNTAX printf (“FORMAT_CONTROL_STRING”, PRINT_LIST); EXAMPLE: printf (“The sum of %lf and %d is\n”, TAX, INTEREST); FORMAT_CONTROL_STRING– may vary from ordinary characters, escape sequence, format specifiers; with double quote/un-quote sign. PRINT_LIST – the actual parameter that printf function class, i.e. constants, variables, expressions or a function call. Format Specifier– the sign specification that converts an internal representation for a data type field to readable data value.

  4. EXAMPLE:- double height = 147.2578 printf (“The value of %f printed in scientific notation is %e is.\n”, height, height); OUTPUT:- The value of 147.257800 printed in scientific notation is 1.472578e+02. Press any key when ready_ OUTPUT FUNCTION OF printf GENERAL SYNTAX printf (“FORMAT_CONTROL_STRING”, PRINT_LIST); EXAMPLE: printf (“The sum of %lf and %d is\n”, TAX, INTEREST); FORMAT_CONTROL_STRING– may vary from ordinary characters, escape sequence, format specifiers; with double quote/un-quote sign. PRINT_LIST – the actual parameter that printf function class, i.e. constants, variables, expressions or a function call. Format Specifier– the sign specification that converts an internal representation for a data type field to readable data value.

  5. Recall format specifiers as the followings:- %d for integers %c for characters %f for floating-points values in conventional notation. (Variations ~ %lf and %Lf) %s for strings

  6. INTERACTIVE INPUT FUNCTIONS scanf -A programmer enters data values for variables while the program is executing. Other standard command : getchar, gets

  7. Syntax of the scanf: Scanf(“FormatControlString”,InputList); Example: scanf(“%lf”,&radius); scanf(“%c%c%c”,&letter_1,&letter_2,&letter_3);

  8. void main(void) { char answer; printf(" Do you like to stay up until 2.00am in the morning? y or n\n"); scanf(“%c”, &answer); printf("%c\n",answer); if (answer == 'y') { printf(" You are hardworking\n"); } else if (answer == 'n') { printf(" You are very lazy\n"); } else putchar(answer); }

  9. CHARACTER INPUT & OUTPUT SINGLE CHARACTER INPUT FROM KEYBOARD (getchar) Part of the standard I/O library that reads single character from standard input device. Initial declaration is a must. For example:- char ch; Illustration The Statement : ch = getchar ( ); The equivalent statement : scanf(“%c”, &ch);

  10. SINGLE CHARACTER OUTPUT TO SCREEN (putchar) • Writes one character to the standard output unit. • General function reference is written as prototype • statement as the following:- • putchar (character variable) • char ch; • Illustration • The Statement :putchar (ch) • The equivalent statement :printf (“%c”, ch);

  11. TUTORIAL (can be download at : http://fakhrulrozi.com/ 1. Write a C program that print the message “This is a C program.” on one line. 2. Write a C program that print the message that can ask user to input their first name and last name (scanf) produce output that display their full name example outputs for question 2: enter your first name : enter your last name : thank you, your full name is :

More Related