简体   繁体   中英

Core dumped when running C program

I create a C program:

#include <stdio.h>
void user_connect( char user[], char date[]){
FILE* fichier=NULL;
fichier=fopen("log.txt","+a");
fprintf(fichier,"user:%s connected at :%s",user,date);
fclose(fichier);

}

void etat_periph( char periph[]){

FILE* fichier=NULL;
fichier=fopen("log.txt","+a");
fprintf(fichier,periph);
fclose(fichier);

}

int main()
{
    char user[]="user";
    char periph[]="led is on";
    char date[]="02/08/2015";

    user_connect(user,date);
    etat_periph(periph);
    return 0;
}

when I run it I got this error message "segmentation fault(core dumped)" I tried to debugger it but I didn't get any valuable thing to resolve it.

You should change your code to

fichier=fopen("log.txt","a+");

"+a" -> "a+"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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