Error : format'%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]

后端 未结 3 1058
半阙折子戏
半阙折子戏 2021-01-24 10:17

I am currently trying to do my own shell, and it has to be polyglot. So I tryed to implement a function that reads the lines in a .txt file.

#include 

        
3条回答
  •  隐瞒了意图╮
    2021-01-24 10:59

    I'm completely guessing, but I think what you want is:

    #include 
    #include 
    #include 
    
    
    // globals
    char lang[16] = {'t','r','y'};
    char *aMsg[512];
    
    // functions
    void takeFile() {
        int i =0;
        char namFil[32];
        char lg[16];
        FILE * file;
        char tmp[255];
        char * line = tmp;
        size_t len = 0;
        ssize_t read;
    
    
        strcpy(namFil,"/media/sf_Projet_C/");
        strcpy(lg,lang);
        strcat(lg, ".txt");
        strcat(namFil, lg);
        file = fopen(namFil, "r");
        printf("%s\n", namFil);
    
        while((read = getline(&line,&len, file)) != -1) {
            aMsg[i] = malloc(strlen(line)+1);
            strcpy(aMsg[i], line);
            i++;
        }
    
        fclose(file);
    }
    
    enum nMsg {HI, QUIT};
    
    int main(void) {
        takeFile();
        printf("%s\n%s\n", aMsg[HI], aMsg[QUIT]);
    
        free(aMsg[HI]);
        free(aMsg[QUIT]);
    
        return 0;
    }
    

提交回复
热议问题