我们说我有一系列电话号码:5********
我需要找到符合特定模式的电话号码。
例如,我可以找到一个数字:
5
以**2*****
开头,其余数字可以忽略(无论他们真的如何)2
第三位数字为number_matches
,其余数字可以忽略(无论他们真正的是什么)我应该寻找的模式由用户提供。我写了一个简单的测试,但不知怎的,我在实现#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i,j;
char *findmeplz = "5********";
char numbers[4][9] = {"555555534", "112221222", "512221222", "355555534"};
for (i=0; i<4; i++)
{
if(number_matches(numbers[i], findmeplz))
{
printf("number found on position %d\n", i);
break;
}
}
return 0;
}
函数方面遇到了问题。
if (!client.connect("api.apixu.com", 80)) {
Serial.println("connection failed");
return;}
client.print("GET " + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/json\r\n" +
"Connection: close\r\n\r\n");
char c[1024];
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
c[0] = client.read();Serial.print(c);}
答案 0 :(得分:1)
该功能如下:
int number_matches(char* number, char* pattern)
{
int i = 0, flag = 1;
for(i = 0; i < strlen(pattern); i++)
{
if(pattern[i] != '*')
{
if(pattern[i] != number[i])
{
flag = 0;
break;
}
}
}
return flag;
}