#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <curses.h>
void strncpy_(char *s,char *t,int n)
{
    while(*t && n-- > 0)
        *s++ = *t++;
    while(n-- > 0)
        *s++ = '\0';
}
void strncat_(char *s,char *t,int n)
{
    while(*s)
        s++;
    while((*s++ = *t++) && n-- > 0)
        ;
}
int strncmp_(char *s,char *t,int n)
{
    for( ; *s == *t;s++,t++)
        if(*s == '\0' || --n <= 0)
            return 0;
    return *s - *t;
}
int main()
{
    char *c = "Ilove you!";;
    char *p = "Ilpe ni!" ;

    int n = 3;
    int i;

    i = strncmp_(c,p,n);

    printf("%d",i);

    return 0;

}


主函数调用strncmp,该函数返回字符串ASCII码差值。

 

相关文章:

  • 2022-02-24
  • 2021-10-03
  • 2022-02-12
  • 2021-08-13
  • 2021-11-12
  • 2021-11-10
  • 2022-02-24
  • 2021-07-09
猜你喜欢
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-10-08
相关资源
相似解决方案