C中常用方法总结
1. 计算字符串长度
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define uint16_t int
uint16_t xstrlen(const char *s)
{
int n;
for(n = 0; *s != '\0'; s++)
{
n++;
}
return n;
}
int main(){
const char *str = "Hello,World!";
uint16_t len = xstrlen(str);
printf("值:%d\n",len);
return 0;
}