This week in general, most of the time is in the review of the previous period of knowledge, I think the front of the better understanding, is to the function of the time do not know how to separate, so every time to separate the time is difficult to start. Review the time has been to see this basically know how to use, and yesterday used the strcmp (comparison) how this use
12345678910 |
//题:比较字符串
//要看ASII表 A:65,a:95
#include<stdio.h>
#include "1.c"
int
main(
void
){
char
a[] =
"Aaa"
;
char
b[] =
"aa"
;
int
num = compare(a,b);
printf
(
"%d"
,num);
}
|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
#include<stdio.h>
int
compare(
char
a[],
char
b[]){
int
bLenth,aLenth;
//声明
int
i = 0,j = 0,k = 0,num = 0;
int
o;
//计算字符数组的长度
while
(a[i]!=
‘\0‘
){
i++;
}
aLenth = i;
//计算字符数组a的长度
while
(b[j]!=
‘\0‘
){
j++;
}
bLenth = j;
//计算字符数组b的长度
//printf("a数组的长度为:%d,b数组的长度为:%d\n",aLenth+1,bLenth+1);
//谁短取谁
if
(aLenth>=bLenth){
o = bLenth;
//aLenth = i;赋值给o;
}
else
{
o = aLenth;
//
}
//
for
(k;k<o;k++){
if
((
int
)a[k]>(
int
)b[k]){
//将字符串转换成int型,
return
1;
}
else
if
((
int
)a[k]==(
int
)b[k]){
num++;
//
continue
;
}
else
{
return -1;
}
}
//
if
(num==o){
if
(aLenth>bLenth){
return
1;
}
else
if
(aLenth<bLenth){
return
-1;
}
else
{
return
0;
}
}
}
|
This is the use of strcmp. There is usually a little reading, yesterday review when a lot of theoretical knowledge can not be answered, and take one or two days to read more reading.
The learning situation this week