当前位置:网站首页>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
边栏推荐
- Element calculation distance and event object
- ES6 new method
- JS get link? The following parameter name or value, according to the URL? Judge the parameters after
- Gaode map search, drag and drop query address
- 【Appium】通过设计关键字驱动文件来编写脚本
- C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
- Kubernetes 服务发现 监控Endpoints
- Applet learning notes (I)
- 云原生虚拟化:基于 Kubevirt 构建边缘计算实例
- 587. 安装栅栏 / 剑指 Offer II 014. 字符串中的变位词
猜你喜欢
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
.105Location
Applet learning notes (I)
Future usage details
C1小笔记【任务训练篇二】
Go的Gin框架学习
Implementation of k8s redis one master multi slave dynamic capacity expansion
394. String decoding - auxiliary stack
48. Rotate image
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
随机推荐
Arithmetic expression
Using files to save data (C language)
开源按键组件Multi_Button的使用,含测试工程
122. The best time to buy and sell stocks II - one-time traversal
Go's gin framework learning
Halo open source project learning (II): entity classes and data tables
31. Next arrangement
In JS, t, = > Analysis of
C1 notes [task training chapter I]
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
198. Looting - Dynamic Planning
Add drag and drop function to El dialog
402. Remove K digits - greedy
Go file operation
1217_ Generating target files using scons
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
Chrome浏览器的跨域设置----包含新老版本两种设置
239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
关于gcc输出typeid完整名的方法