利用c语言函数调用写strcmp,strncmp
来源:互联网 发布:软件测试的心得体会 编辑:程序博客网 时间:2024/05/22 00:51
通过函数调用,对字符串进行操作
#include<stdio.h>
#define N 10
int Strcmp(char *str1, char *str2)
{
int j;
int i;
int len = 0;
for (i = 0,j = 0; *(str1+i) != '\0'; i++,j++)
{
len++;
if (*(str1+i) != *(str2+j))
{
if (*(str1+i) > *(str2+i))
{
return 1;
}
else
{
return -1;
}
}
for (i = 0; i < len; i++)
{
while (*(str1+i) == *(str2+i))
{
return 0;
}
}
}
}
int main()
{
char a[N];
char b[N];
scanf ("%s %s",a,b);
Strcmp(a,b);
printf("%d\n",Strcmp(a,b));
}
#include<stdio.h>
#define N 10
int Strncmp(char *str1, char *str2, int n)
{
int i = 0;
int temp;
while (i <= n)
{
if (*(str1+i) != *(str2+i))
{
if (*(str1+i) > *(str2+i))
{
temp = 1;
break;
}
else
{
temp = -1;
break;
}
}
else
{
temp = 0;
}
i++;
}
return temp;
}
int main()
{
char a[N];
char b[N];
int n;
scanf("%s %s %d",a,b,&n);
printf("%d\n",Strncmp(a,b,n));
}
- 利用c语言函数调用写strcmp,strncmp
- 【C语言】模拟实现strcmp()、strncmp()函数
- C语言 模拟实现strcmp strncmp
- 用C语言 实现strcmp(),strncmp()相同功能的myStrcmp()函数和myStrncmp()函数
- strcmp,strncmp函数
- strcmp,strncmp ,memcmp函数
- C strcmp 与 strncmp
- C strcmp 与 strncmp
- C语言函数strcmp
- 编写类似strcmp() strncmp()函数
- 实现strcmp( )和strncmp( )函数
- 模拟实现strcmp strncmp函数
- 用C语言实现strncmp函数
- 杂记之C语言函数strncmp
- strcmp函数 strncmp函数 strcmpi,stricmp函数
- C语言之strcmp函数
- C语言实现strcmp函数
- strcmp() , strncmp();
- java基础之自增自减
- PAT B1017
- 粒子滤波学习笔记(四)
- 嵌入式开发面试题
- apache commons 工具包
- 利用c语言函数调用写strcmp,strncmp
- 88. Merge Sorted Array#1(Done)
- PAT B1019
- Java中extends 与 implement 区别
- malloc实现原理
- java动态编译时候空指针异常解决方式
- TextView实现跑马灯效果
- 矩阵乘法总结
- Sqlite的使用详解