? ? ? ? 做个笔录
1、示例1
#include <stdio.h>
#include <string.h>
#include "main.h"
struct strStruct
{
uint16_t phone_num[16];
uint16_t message[400];
};
void filterSpaces(char* src, char* dst)
{
uint8_t i = 0;
uint8_t flag = 0;
char* p = NULL;
for (p = src; *p != '\0'; p++) {
if (*p == ':') {
flag = 1; //android
}
if (*p == ' ') {
flag = 2; //ios
}
}
/* andorid */
if (flag == 1) {
for (p = src; *p != ':'; p++) {
/*if (*p == ':') {
break;
}*/
dst[i++] = *p;
}
}
/* ios */
if (flag == 2) {
/* p=str indicates that the pointer points to the first address of the string to mark */
for (p = src; *p != '\0'; p++) {
/* Not equal to '\0' means p++ as long as the string does not end. */
if (*p != ' ') {
dst[i++] = *p;
}
}
}
}
int main(void)
{
struct strStruct str, str1;
memcpy(str.phone_num, "13578942356", sizeof("13578942356"));
// memcpy(str.message, "135 7894 2356", sizeof("135 7894 2356"));
memcpy(str.message, "来来来:13578942356", sizeof("13578942356"));
printf("111 %s, %s\n", (char*)str.message, (char*)str1.message);
filterSpaces((char*)str.message, (char*)str1.message);
printf("222 %s, %s\n", (char*)str.message, (char*)str1.message);
int res = strcmp((char*)str1.message, (char*)str.phone_num);
// char* res = strstr((char*)str1.message, (char*)str.input_num);
if (res == 0)
//if (res != NULL)
{
printf("两个字符串相等!");
}
else
{
printf("两个字符串不相等!");
}
printf("heihei");
}
2、示例2:?
#include <stdio.h>
#include <string.h>
#include "main.h"
struct strStruct
{
uint16_t phone_num[16];
uint16_t message[400];
};
uint8_t filterSpacesColon(uint16_t* src, uint16_t* dst)
{
uint8_t index = 0;
uint8_t flag = 0;
uint16_t* p = src;
while(*p != '\0')
{
if (*p == ':') {
flag = 1; //android
break;
}
if (*p == ' ') {
flag = 2; //ios
break;
}
p++;
}
/* andorid */
if (flag == 1) {
for (p = src; *p != '\0'; p++, dst++) {
if (*p == ':') {
break;
}
*dst = *p;
index++;
}
}
/* ios */
if (flag == 2) {
/* p=str indicates that the pointer points to the first address of the string to mark */
for (p = src; *p != '\0'; p++) {
/* Not equal to '\0' means p++ as long as the string does not end. */
if (*p != ' ') {
dst[index++] = *p;
}
}
}
return index;
}
int main(void)
{
filterSpacesColon(str.message, message);
printf("222 %s, %s\n",str.message, message);
for (int i = 0; i < 32; i++)
{
printf("0x%x", message[i]);
}
}
3、运行结果: