当前位置:网站首页>Manual string comparison (pointer question)
Manual string comparison (pointer question)
2022-07-19 06:54:00 【winkiii】
describe
Write a function , Realize the comparison of two strings . That is to write one by yourself strcmp function , The function prototype is strcmp(char *p1,char *p2), set up p1 Point to string s1,p2 Point to string s2. Ask to be s1=s2 when , The return value is 0;(s1,s2 The length is equal and does not exceed 100) if s1!=s2, Return the first different character between them ASCII Code difference ( Such as “BOY” And “BAD”, The first 2 Different letters ,“O” And “A” The difference is 79-65=14); If s1>s2, Then a positive value is output , Otherwise, negative value is output .( This question requires using a pointer )
Input
First act N, It means that there is N Group test data . Next N Row representation N Group test data , Each set of test data contains two strings , Space separates the middle , And ensure that the characters in each string are lowercase .
Output
Output the result of two string comparison .
sample input 1
2
abcdef aaaaaa
a z
sample output 1
1
-25
#include<stdio.h>
int strcmp(char *p1,char *p2){
while(*p1 && *p2 && (*p1==*p2)){
p1++;
p2++;
}
return *p1-*p2;
}
int main(){
int n,i,t;
char s1[100],s2[100];
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++){
scanf("%s %s",&s1,&s2);
t = strcmp(s1,s2);
printf("%d\n",t);
t = 0;
}
}
}
边栏推荐
猜你喜欢

F5LTM(一)逻辑关系图

opensuse 安装网易云音乐(tumbleweed)(leap)

Drawing PCB with Altium Designer

Pytorch deep learning practice-b station Liu erden-day6

通过数据加密方案阻止勒索攻击

Binary search and its extension
![[ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :](/img/dd/054af819c8bdca31bd135495386fb4.png)
[ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :

Pytorch deep learning practice-b station Liu erden-day3

Zuul路由的映射规则配置

TCP/IP四层模型以及F5部分相关配置
随机推荐
F5 GTM (I): DNS parameters
伺服电机的电子齿轮比如何确定?
TCP/IP四层模型以及F5部分相关配置
Share the successful cooperation between CS brand sdnand and wearable devices
锁
ANAME
How can the new generation of CS sdnand (also known as patch T card) make the old MCU youthful
关于文件上传下载问题
Gentoo安装教程(Systemd+Gnome)
毛毛上班(递推)
slackware 14.2 安装KDE 5 plasma
Generate audio and waveform in PWM and DAC exercises of stm32
Vcenter6.7 installation and troubleshooting
Pytorch deep learning practice-b station Liu erden-day4
2022-7-15 cheap domestic PLC industrial control board with scattered records of 485 master-slave communication
How to make good use of cost compensation contract in government procurement
C language structure array pointer and function
notepad++下划线以及大小写字母置换
redis
聊聊中台:我对中台的一些理解与思考