INPUT AND OUTPUT STATEMENTS Class : I B.Sc Cyber Security Subject : Coding Techniques Subject Code : U24EM101 Presented By Mr. S.Vignesh (AP/CS) Department of Computer Science
Introduction I nput → getting data from user Output → displaying data to user C uses < stdio.h > (Standard Input/Output) header file Provides functions like scanf (), printf (), etc.
Input Functions scanf () → formatted input getchar () → read single character fgets () → read string safely scanf () It is used to read user input from the console. It takes the format string and the addresses of the variables where the input will be stored. SYNTAX scanf (" formatted_string ", address_of_variables /values);
g etchar () It reads a single character from the keyboard.
fgets () fgets () reads the given number of characters of a line from the input and stores it into the specified string. It can read multiple words at a time
Output Functions printf () → formatted input put char () → read single character puts() → read string safely printf () The printf () function is used to print formatted output to the standard output stdout (which is generally the console screen). It is one of the most commonly used functions in C. SYNTAX printf (" formatted_string ", variables/values);
put char () It prints a single character to the screen.
fputs () The fputs () function is used to output strings to the files but we can also use it to print strings to the console screen. It just print text only and not supported formatted output like printf