Why my bzero() cause a bus error with my char array?

231 Views Asked by At

I try to understand why my simple code who use bzero or memset cause a bus error with clangor gcc I find no logical explication.

I try the simple example from this post : Proper way to empty a C-String

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    char *str;
    printf("%lu\n",strlen(str));
    bzero(str,1); // ok
    str = "bonjour";
    bzero(str,strlen(str)); // bus error
    // memset(str, 0, strlen(str)); // bus error
    return(0);
}
0

There are 0 best solutions below