⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 environhostname.c

📁 从environ获得HostName
💻 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 + -