例如,要验证有效的Url,我想执行以下操作
char usUrl[MAX] = "http://www.stackoverflow"
if(usUrl[0] == 'h'
&& usUrl[1] == 't'
&& usUrl[2] == 't'
&& usUrl[3] == 'p'
&& usUrl[4] == ':'
&& usUrl[5] == '/'
&& usUrl[6] == '/') { // what should be in this something?
printf("The Url starts with http:// \n");
}
Run Code Online (Sandbox Code Playgroud)
或者,我考虑过使用strcmp(str, str2) == 0,但这一定非常复杂.
是否有标准的C函数可以做这样的事情?
假设我们有两个不同的struct主要是常见字段,但有一个或两个不同的字段或更少的字段.例如:
typedef struct HobbyNodetag {
char *name; // hobby name
struct HobbyNodetag* link; // link to next HobbyNode
int count; // number of times this hobby was mentioned by user
// more fields...
// but identical type/variable name with MyHobbyList
} HobbyNode; // database of entire hobby node; singly linked list
typedef struct MyHobbyTag{
char *name; // hobby name
struct MyHobbyTag* link; // linked to next MyHobbyNode
// more fields...
// but identical type/variable name with EntireHobbyList
} …Run Code Online (Sandbox Code Playgroud) 缓冲区字符串char *bufferString指向以下字符串的第一个元素:
BER Berman,Jane 06/29/91摄影;舞蹈;音乐\n
我想解析最后一个主题列表中的每个主题项并存储它们
我尝试过的:
#define REGEX_TOPIC "^[a-zA-Z].*^[0-9/0-90-9/0-90-9+]"
char *topic;
topic = strstr(bufferString, REGEX_TOPIC);
Run Code Online (Sandbox Code Playgroud)
你能帮帮我吗?