COMP 206 Lecture Notes - Lecture 17: Data File, Carriage Return, Segmentation Fault

47 views4 pages

Document Summary

We were talking about basic input and output operations: getchar() and fgetc(filehandle) return one character at a time as an int. So to use the output in a character string, you must be comfortable with converting between integers and character types in c. Use a character variable and just say char c = [value] . Be careful about type conversions and it should work fine. The reason why they don"t return char (which would be sensible because they"re supposed to be reading text from files) is because that isn"t their only goal. They can also read binary data, and it doesn"t necessarily make sense to use a char cata type because we aren"t reading string-type data. Int is the most flexible , and importantly, there"s at least one special return code, which is end-of-file , to tell you when to stop reading. End-of-file is returned by input functions when they can no longer give useful input:

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents