?? environhostname.c
字號:
#include <stdio.h>#include <string.h>int main(int argc, char **argv)//int main(int argc, char *argv[]){ extern char **environ; char **p; int i = 0; char token[128]; char value[1024]; for (p = environ; *p != NULL; p++) { i++; fprintf(stdout, "%4d:%s\n", i, *p); // char *strchr(const char *s, int c); char *pos; // Upon completion, strchr() shall return a pointer to the byte, or a null pointer if the byte was not found. pos = strchr(*p, '='); //fprintf(stdout, "debug: pos = %c\n", *pos); if (pos == NULL) { fprintf(stderr, "cannot find token.\n"); break; } memset(token, 0, sizeof(token)); memcpy(token, *p, pos - *p); //token[pos-*p] = '\0'; //fprintf(stdout, "debug: token = %s\n", token); memset(value, 0, sizeof(value)); memcpy(value, pos + 1, strlen(*p) - (pos - *p + 1)); fprintf(stdout, "debug: value = %s\n", value); if (!strcmp(token, "HOSTNAME")) { fprintf(stdout, "found it! HOSTNAME=%s\n", value); } } return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -