1 / 21

ACM TRAINING COURSE

Class #1 Data Types Inputs/Outputs. ACM TRAINING COURSE. Data Types . char (signed or unsigned) int (signed or unsigned) double (signed or unsigned) float (signed or unsigned) void. Inputs. int scanf ( const char * format, ... );. Whitespace Non-whitespace character (except %)

silver
Download Presentation

ACM TRAINING COURSE

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. Class #1 Data Types Inputs/Outputs ACM TRAINING COURSE

  2. Data Types • char (signed or unsigned) • int (signed or unsigned) • double (signed or unsigned) • float (signed or unsigned) • void

  3. Inputs

  4. int scanf ( const char * format, ... ); • Whitespace • Non-whitespace character (except %) • Format specifiers • %[*][width][modifier]type

  5. Format Specifiers

  6. Type

  7. Return Value • On success, the function returns the number of items succesfully read. (This count can match the expected number of readings or fewer, even zero, if a matching failure happens.) • In the case of an input failure before any data could be successfully read, EOF is returned.

  8. char * gets ( char * str ); • Reads characters from stdin and stores them as a string into str until a newline character ('\n') or the End-of-File is reached.The ending newline character ('\n') is not included in the string.A null character ('\0') is automatically appended after the last character copied to str to signal the end of the C string.

  9. fgets vs gets • Notice that gets does not behave exactly as fgets does with stdin as argument: First, the ending newline character is notincluded with gets while with fgets it is. And second, gets does not let you specify a limit on how many characters are to be read, so you must be careful with the size of the array pointed by str to avoid buffer overflows.

  10. Return Value • On success, the function returns the same str parameter. • If the End-of-File is encountered and no characters have been read, the contents of str remain unchanged and a null pointer is returnes. • If an error occurs, a null pointer is returned.

  11. int getchar ( void ); • The character read is returned as an int value.If the End Of File is reached or a reading error happens, the function returns EOF and the corresponding error or eof indicator is set.

  12. Outputs

  13. int printf ( const char * format, ... ); • String that contains the text to be written to stdout. It can optionally contain embedded format tags that are substituted by the values specified in subsequent argument(s) and formatted as requested.The number of arguments following the format parameters should at least be as much as the number of format tags.The format tags follow this prototype:%[flags][width][.precision][length]specifier

  14. Flags and Width

  15. Precision and Length

  16. Specifiers

  17. Return Value • On success, the total number of characters written is returned. • On failure, a negative number is returned.

  18. int puts ( const char * str ); • Writes the C string pointed by str to stdout and appends a newline character ('\n').The function begins copying from the address specified (str) until it reaches the terminating null character ('\0'). This final null-character is not copied to stdout. • Using fputs(str,stdout) instead, performs the same operation as puts(str) but without appending the newline character at the end.

  19. Return Value • On success, a non-negative value is returned. • On error, the function returns EOF.

  20. Exercise • TEX Quotes • Soundex Indexing • WERTYU • Word Scramble

  21. bibliography • www.google.com • http://www.cplusplus.com/

More Related