Segmentation Fault When Passing Struct to Function in C - Unsure Why
I recently switched to I'm building a feature where I'm maintaining legacy code that I'm working with a segmentation fault when I attempt to pass a struct to a function in my C program..... The struct is defined as follows: ```c typedef struct { int id; char name[50]; } Person; ``` I have a function that takes a pointer to this struct as an argument: ```c void printPerson(Person *p) { printf("ID: %d, Name: %s\n", p->id, p->name); } ``` In my `main` function, I create a `Person` instance and call `printPerson` like this: ```c int main() { Person john; john.id = 1; strcpy(john.name, "John Doe"); printPerson(&john); return 0; } ``` However, when I run the program, I get a segmentation fault. I've checked the initialization of the `john` variable, and it seems fine. I suspect it could be related to how I'm using the struct pointer, but I need to pinpoint the scenario. I've also tried compiling with different flags such as `-Wall` and `-Wextra`, but no additional warnings are provided. Can anyone guide to understand why this segmentation fault is occurring? Is there something I'm missing in the way I'm passing the struct pointer, or could it be an scenario elsewhere in my code? I'm developing on Debian with C. What's the correct way to implement this? What would be the recommended way to handle this? For context: I'm using C on CentOS. Any suggestions would be helpful.