InputandOutputinC输入和输出C

上传人:ra****d 文档编号:252426598 上传时间:2024-11-15 格式:PPT 页数:12 大小:42KB
收藏 版权申诉 举报 下载
InputandOutputinC输入和输出C_第1页
第1页 / 共12页
InputandOutputinC输入和输出C_第2页
第2页 / 共12页
InputandOutputinC输入和输出C_第3页
第3页 / 共12页
资源描述:

《InputandOutputinC输入和输出C》由会员分享,可在线阅读,更多相关《InputandOutputinC输入和输出C(12页珍藏版)》请在装配图网上搜索。

1、Click Here to Add Title,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,C Programming,Lecture 3,:I/O in C,printf()scanf(),Input/Output in C,C has no built-in statements for input or output.,A library of functions is supplied to perform these operations.The I/O libr

2、ary functions are listed the“header file.,You do not need to memorize them,just be familiar with them.,Streams,All input and output is performed with streams.,A stream is a sequence of characters organized into lines.,Each line consists of zero or more characters and ends with the newline character.

3、,ANSI C standards specify that the system must support lines that are at least 254 characters in length(including the newline character).,Types of Streams in C,Standard input stream is called stdin and is normally connected to the keyboard,Standard output stream is called stdout and is normally conn

4、ected to the display screen.,Standard error stream is called stderr and is also normally connected to the screen.,Formatted Output with printf,The printf()function prints output to stdout,according to format and other arguments passed to printf().The syntax is:,printf(“format,var1,var2,);,The string

5、 format consists of two types of items-characters that will be printed to the screen,and format commands that define how the other arguments to printf()are displayed.Basically,you specify a format string that has text in it,as well as special characters that map to the other arguments of printf().Fo

6、r example:,char name20=Bob;int age=21;printf(Hello%s,you are%d years oldn,name,age);,Hello Bob,you are 21 years old,Formatted Output with printf,Format Conversion Specifiers:,d-displays a decimal(base 10)integer,l-used with other specifiers to indicate a long,e-displays a floating point value in exp

7、onential notation,f-displays a floating point value,g-displays a number in either e or f format,c-displays a single character,s-displays a string of characters,i,-,signed integer,u-unsigned integer,x-unsigned hexadecimal,with lowercase letters,o-octal,%-a%sign,Formatted input with scanf();,The scanf

8、()function reads input from stdin,according to the given format,and stores the data in the other arguments.The syntax is:,scanf(“format,It works a lot like printf().The format string consists of control characters,whitespace characters,and non-whitespace characters.,Example:,float a;int b;,scanf(“%f

9、%d,scanf()reads the input,matching the characters from,format,.When a control character is read,it puts the value in the next variable.Whitespace(tabs,spaces,etc)are skipped.Non-whitespace characters are matched to the input,then discarded.If a number comes between the%sign and the control character

10、,then only that many characters will be converted into the variable.If scanf()encounters a set of characters,denoted by the%control character,then any characters found within the brackets are read into the variable.The return value of scanf()is the number of variables that were successfully assigned

11、 values,or,EOF,if there is an error.,Input/Output in C,getchar();,This function provides for getting exactly one character from the keyboard.,Example:,char ch;,ch=getchar();,Input/Output in C,putchar(char);,This function provides for printing exactly one character to the screen.,Example:,char ch;,ch

12、=getchar();/*input a character from kbd*/,putchar(ch);/*display it on the screen*/,Input/Output in C,getc(*file);,This function is similar to getchar()except the input can be from the keyboard or a file.,Example:,char ch;,ch=getc(stdin);/*input from keyboard*/,ch=getc(fileptr);/*input from a file*/,Input/Output in C,putc(char,*file);,This function is similar to putchar()except the output can be to the screen or a file.,Example:,char ch;,ch=getc(stdin);/*input from keyboard*/,putc(ch,stdout);/*output to the screen*/,putc(ch,outfileptr);/*output to a file*/,

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

相关资源

更多
正为您匹配相似的精品文档
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!