简体   繁体   English

尝试获取主目录时的隐式声明警告

[英]implicit declaration warning when trying getting home directory

I type this code to get the home directory. 我键入以下代码以获取主目录。 I have later edited it to include all of the code: 我后来对其进行了编辑,以包括所有代码:

#include <math.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <stdarg.h>
#include "anotherfile.h"

typedef unsigned int uint;

void Interval(void) {
    static uint S = 0;
    static uint C = 0;
    static uint M = 0;
    static uint D = 0;
    usleep(10e5/0x20);
    printf("%d\n", C);
    printf("%d\n", S);
    printf("%d\n", M);
    if(C == 0x20) {
        if(S == 59) {
            S=0;
            M++;
        }else{S++;}
        C=0;
    }else{C++;}
    Interval();
}

int main(int argc, const char *argv[]) {
    char *HomeDir;
    if((HomeDir = getenv("HOME")) == NULL) {
        HomeDir = getpwuid(getuid())->pw_dir;
        if(HomeDir == NULL) {
            printf("Failed to get Home Directory\n");
        }else{printf("Retry Home Directory Found\n");}
    }else{printf("Success getting Home Directory\n");}
    Interval();
    return 0;
}

It gives me the implicit declaration warning. 它给了我隐式声明警告。 It says something is wong with the getenv partHow can I fix it? 它说getenv出了点问题我该如何解决?

The function getenv is declared in stdlib.h according to this reference. 根据参考,在stdlib.h声明了功能getenv So you need to add 所以你需要添加

#include <stdlib.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM