警告:传递参数会使指针来自整数

时间:2017-03-25 08:43:07

标签: c

    struct config_struct {
    int port; };

 void read_int_from_config_line(char* config_line, int* val) {
    char prm_name[MAX_VARIABLE_LEN];
    sscanf(config_line, "%s %d\n", prm_name, val); }

void read_config_file(char* config_filename, struct config_struct config) {
    FILE *fp;
    char buffer[MAX_BUFFER_SIZE];

    fp= fopen("settings.conf", "r");
    if (fp == NULL)
    printf("Config file does not exist, Creating one.../n");
    {
        fp = fopen("settings.conf", "w+");
        fputs("NAME:Root\nIP:192.168.0.1\nPORT:20\nLOGFILE:\n", fp);
    }
    while (fscanf(fp, "%s", buffer) != EOF)
    {
        fgets(buffer, MAX_BUFFER_SIZE, fp);
        if (buffer[0] == '#') {
            continue;
        }
        if(!strcmp(buffer,"PORT:")) {
            read_int_from_config_line(buffer ,config.port);
        }
    }
    fclose(fp);

我收到警告passing argument 2 of ‘read_int_from_config_line’ makes pointer from integer without a cast read_int_from_config_line(buffer,config.port);

我可以知道如何解决这个问题?我可能是C的完全白痴,因为我刚刚开始4周前。一些帮助将不胜感激。感谢

1 个答案:

答案 0 :(得分:0)

我需要看看你是如何调用这个函数的。我可以说你正在尝试打印指针指向的位置,而不是值。要打印值* val。