当前位置:网站首页>C language input and output (printf and scanf functions, putchar and getchar functions)
C language input and output (printf and scanf functions, putchar and getchar functions)
2022-04-23 17:57:00 【Chshyz】
printf and scanf function 、putchar and getchar function
Input and output operations are performed by C Functions in the standard function library , Use preprocessing instructions at the beginning of the program file #include Put relevant documents in this procedure #include<stdio.h>
One 、printf() Output details :printf( Format control , Output table columns )
- Format control is a string enclosed in double quotation marks . Abbreviation format string , for example :“%d”.
- The output list is some data that the program needs to output , It can be a constant 、 Variable or table , for example a.
#include<stdio.h>
int main(){
printf("ddddd\n");
}
~
[[email protected] c]# ./printf
ddddd
#include<stdio.h>
int main(){
int a = 100;
printf("%d\tdddd\n",a); // \t There are four spaces
}
~
[[email protected] c]# ./printf
100 dddd
#include<stdio.h>
int main(){
int a = 100;
printf("%d,%d,%d\n",a,a,a++);
}
[[email protected] c]# ./printf
101,101,100
#include<stdio.h>
int main(){
int a = 100;
printf("%d,%d,%d\n",a,a++,a++);
}
[[email protected] c]# ./printf
102,101,100
#include<stdio.h>
int main(){
int a = 100;
printf("%d,%d,%d\n",a,a,++a);
}
[[email protected] c]# ./printf
101,101,101
Two 、scanf() Enter details :scanf(% Format characters , Variable address )
#include<stdio.h>
int main(){
int a;
scanf("%d",&a);
}
[[email protected] c]# ./scanf
2
#include<stdio.h>
int main(){
int a, b;
scanf("%d,%d",&a,&b);
printf("%d,%d\n",a,b);
}
[[email protected] c]# ./scanf
2,3
2,3
3、 ... and 、getchar() and putchar(), Input and output single characters .
- putchar() Output ( Anyone who ASCLL You can put any size ).
#include<stdio.h>
int main(){
char chshyz = 97;
putchar(chshyz);
return 0;
}
~
[[email protected] c]# ./putchar
a
- getchar() Input , It has no parameters .
#include<stdio.h>
int main(){
char chshyz;
chshyz = getchar();
printf("%c\n",chshyz);
return 0;
}
~
[[email protected] c]# ./getchar
chshyz
c
PS: Count the number of upper and lower case letters of the input string ( One letter circulates once )
#include<stdio.h>
int main(){
char chshyz;
int small = 0;
int big = 0;
int i = 0;
for(chshyz = getchar(); chshyz!='\n';){
if (chshyz >= 'a' && chshyz <= 'z') // The comparison is ASCLL code
small++;
else if (chshyz >= 'A' && chshyz <= 'Z')
big++;
chshyz = getchar();
i++;
printf(" The first %d Secondary cycle \n", i);
}
printf(" A lowercase letter :%d individual \t Capitalization :%d individual \n", small, big);
return 0;
}
~
[[email protected] c]# ./getchar
Chshyz
The first 1 Secondary cycle
The first 2 Secondary cycle
The first 3 Secondary cycle
The first 4 Secondary cycle
The first 5 Secondary cycle
The first 6 Secondary cycle
A lowercase letter :5 individual Capitalization :1 individual
版权声明
本文为[Chshyz]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230547413515.html
边栏推荐
- C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
- Timestamp to formatted date
- Hcip fifth experiment
- 20222 return to the workplace
- Fashion classification case based on keras
- 2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
- 31. Next arrangement
- Operators in C language
- Using files to save data (C language)
- Special effects case collection: mouse planet small tail
猜你喜欢
随机推荐
Tensorflow tensor introduction
2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
198. Looting - Dynamic Planning
C# 网络相关操作
587. 安装栅栏 / 剑指 Offer II 014. 字符串中的变位词
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]
92. Reverse linked list II byte skipping high frequency question
Index: teach you index from zero basis to proficient use
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
Implementation of object detection case based on SSD
402. Remove K digits - greedy
JS parsing and execution process
cv_ Solution of mismatch between bridge and opencv
Use of list - addition, deletion, modification and query
Halo 开源项目学习(二):实体类与数据表
Add animation to the picture under V-for timing
Gets the time range of the current week
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
土地覆盖/利用数据产品下载
The method of changing a value in the array and a value in the object of wechat applet