mystrcat
/*************************************************************************
> File Name: mystrcat.c
> Author:
> Mail:
> Created Time: 2017年10月27日 星期五 10时41分03秒
************************************************************************/
#include<stdio.h>
char *mystrcat(char *str1,char *str2);
int main()
{
char str1[128] = {0};
char str2[128] = {0};
gets(str1);
gets(str2);
// str3 = mystrcat(str1,str2);
puts(mystrcat(str1,str2));
return 0;
}
char *mystrcat(char *str1,char *str2)
{
int i=0,j=0,k=0;
static char str3[256] = {0};
for( ;str1[i] != '\0'; )
{
str3[k++] = str1[i++];
}
for(; str2[j] != '\0' ;)
{
str3[k++] = str2[j++];
}
str3[k++] = '\0';
return str3;
}
mystrcmp
/*************************************************************************
> File Name: mystrcmp.c
> Author:
> Mail:
> Created Time: 2017年10月27日 星期五 10时42分55秒
************************************************************************/
#include<stdio.h>
int mystrcmp(char *str1,char *str2);
int main()
{
char str1[128] = {0};
char str2[128] = {0};
gets(str1);
gets(str2);
printf("%d\n",mystrcmp(str1,str2));
return 0;
}
int mystrcmp(const char *str1,const char *str2)
{
int i=0,j=0,k=0;
if(str2 == NULL || str1 ==NULL)
{
return -1;
}
while(str1[i]!='\0' && str2[j]!='\0')
{
if ( str1[i] == str2[j])
{
i++;
j++;
}
else
{
return str1[i]-str2[j];
}
}
if(str1[i]=='\0' && str2[j]=='\0')
{
return 0;
}
else
{
return str1[i]-str2[j];
}
}
mystrcpy
/*************************************************************************
> File Name: mystrcpy.c
> Author:
> Mail:
> Created Time: 2017年10月27日 星期五 10时47分51秒
************************************************************************/
#include<stdio.h>
char *mystrcpy(char *str1,char *str2);
int main()
{
int n;
char a[128] = {0};
char b[10] = {0};
gets(b);
char *p = NULL;
puts(mystrcpy(a,b));
puts(a);
return 0;
}
char *mystrcpy(char *str1,char *str2)
{
int i = 0,j = 0;
while ( str2[j] != '\0' )
{
str1[i] = str2[j];
j++;
i++;
}
str1[i++] = '\0';
return str1;
}
mystrdel
/*************************************************************************
> File Name: mystrdel.c
> Author:
> Mail:
> Created Time: 2017年10月27日 星期五 10时58分29秒
************************************************************************/
#include<stdio.h>
char *strdel(char *str,char s);
int main()
{
char a[256] = {0};char b;
gets(a);
scanf("%c",&b);
puts(strdel(a,b));
return 0;
}
char *strdel(char *str,char s)
{
int i=0,j;
while(str[i] != '\0')
{
if(str[i] == s)
{
j = i;
while(str[j] != '\0')
{
str[j] = str[j+1];
j++;
}
str[j++] = '\0';
i--;
}
i++;
}
return str;
}
mystrlen
/*************************************************************************
> File Name: mystrlen.c
> Author:
> Mail:
> Created Time: 2017年10月27日 星期五 10时56分35秒
************************************************************************/
#include<stdio.h>
int mystrlen(char *a);
int main()
{
char a[128] = {0};
int b;
gets(a);
printf("mystrlen(a) = %d\n",mystrlen(a));
return 0;
}
int mystrlen(char *a)
{
int i = 0,j = 0;
while( a[i++] != '\0' )
{
j++;
}
return j;
}
计算字符串中子串出现的次数。
/*************************************************************************
> File Name: strnum.c
> Author:
> Mail:
> Created Time: 2017年10月27日 星期五 11时08分43秒
************************************************************************/
#include<stdio.h>
//计算子字符串出现的次数
int strnum(char *str1,char *str2)
{
if(str1 == NULL || str2 == NULL)
{
return -1;
}
int i = 0,j = 0;
int num = 0;
while(str1[i] != '\0')
{
if(str1[i] == str2[j])
{
while(str1[i] == str2[j] && str2[j] != '\0')
{
i++;j++;
}
if(str2[j++] == '\0')
{
num++;
}
j = 0;
}
else
{
i++;
}
}
return num;
}
int main()
{
char str1[1024];
char str2[1024];
gets(str1);
gets(str2);
printf("%d\n",strnum(str1,str2));
return 0;
}
链表反向
void reverse(test* head)
{
test* pe = head;
test* ps = head->next;
while(ps)
{
pe->next = ps->next;
ps->next = head;
head = ps;
ps = pe->next;
}
}