点击(此处)折叠或打开
- #include <Windows.h>
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- int main()
- {
-     char line[] = " name = lily ";
-     char *p = line;
-     p += strspn(p, " \t");
-     char *tmp = strpbrk(p, " \t=");
-     int key_len = tmp - p;
-     char *key = (char *)calloc(sizeof(char), key_len + 1);
-     memcpy(key, p, key_len);
-     p = tmp;
-     p += strspn(p, " \t");
-     if(*p++ != '=')
-     {
-         printf("line parse error\n");
-         return 1;
-     }
-     p += strspn(p, " \t");
-     if(*p == '\r' || *p == '\n')
-     {
-         printf("line parse error\n");
-         return 1;
-     }
-     tmp = strpbrk(p, " \t");
-     int value_len = tmp - p;
-     char *value = (char *)calloc(sizeof(char), value_len + 1);
-     memcpy(value, p, value_len);
-     printf("key = %s, value = %s\n", key, value);
-     free(key);
-     free(value);
-     system("pause");
- }
