小编J. *_*man的帖子

如何检查字符串是否以C中的某个字符串开头?

例如,要验证有效的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函数可以做这样的事情?

c string

9
推荐指数
3
解决办法
3万
查看次数

C:struct少一个字段.如何有效地声明/使用它?

假设我们有两个不同的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)

c struct variable-declaration type-declaration

1
推荐指数
1
解决办法
155
查看次数

这个字符串的正则表达式

缓冲区字符串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)

你能帮帮我吗?

c regex

0
推荐指数
1
解决办法
118
查看次数