Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7922635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:01:58+00:00 2026-06-03T17:01:58+00:00

I am getting a segmentation fault when I run prog.c. I have found that

  • 0

I am getting a segmentation fault when I run prog.c. I have found that it is something with my *char. Here’s the code.

prog.c

#include <stdio.h>
#include "worker.h"
#include "manager.h"
#include "employee.h"

int main(int argc, char **argv) {
  int i;
  Worker boss = (Worker) new_Manager("Carl Cracker", 80000, 1987, 12, 15);
  return 0;       
}

worker.h

#ifndef _WORKER_H_
#define _WORKER_H_

 #define WORKER   char *name;   \
          double salary;    \
          long hireDay; \
          void (*raiseSalary)(Worker this, double byPercent);   

typedef struct Worker_struct* Worker;
struct Worker_struct {
   WORKER;
} Worker_struct;

void raiseSalary(Worker this, double byPercent);

#endif

worker.c

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

#include "worker.h"

void raiseSalary(Worker this, double byPercent) {
  Worker worker = (Worker) this; 
  printf("worker_c: raising salary\n");
  double raise = worker->salary * byPercent / 100;
  worker->salary = worker->salary + raise;
}

manager.h

#ifndef _MANAGER_H_
#define _MANAGER_H_

#include "worker.h"


typedef struct Manager_struct* Manager;
struct Manager_struct {
  WORKER;
  double bonus;
void (*setBonus)(Worker this, double b);
} Manager_struct;

Manager new_Manager(char *name, double salary, int year, int month, int day);
#endif

manager.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include "manager.h"

static void setBonus(Worker this, double b) {
  Manager manager = (Manager) this; 
  manager->bonus = b;
}

Manager new_Manager (char *name, double salary, int year, int month, int day) {
  Manager manager;
  strcpy (manager->name, name);//----i think my problem is here----
 manager->salary = salary;
 manager->bonus = 0;    
 manager->setBonus = setBonus;
 manager->raiseSalary = raiseSalary;

return manager;
}

I think that my problem is in the manager.c at strcpy. What am i doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:02:00+00:00Added an answer on June 3, 2026 at 5:02 pm

    You’ve declared char *name in the WORKER macro, but memory hasn’t been allocated to it.

    Please, please don’t define variables in macros like this; there’s absolutely no benefit, and it complicates the code unnecessarily. Just define them directly in the Worker_struct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a segmentation fault everytime i want to run this code : from
Getting a segmentation fault for the following code. Please advise. struct columns { char*
I am getting a Segmentation fault (core dumped) run-time error with the following code:
I am getting a segmentation fault error when I run this code. I don't
Possible Duplicate: Getting Segmentation Fault // reverse a string #include`<stdlib.h>` #include`<stdio.h>` #include`<string.h>` #include`<math.h>` int
Here is my code, #include<signal.h> #include<stdio.h> int main(int argc,char ** argv) { char *p=NULL;
I am getting segmentation fault in this code but i cant figure out why.
I am getting a segmentation fault with the following code after adding structs to
I'm getting a segmentation fault trying to compile the following code. My question is,
I have a C program below written on UNIX. I am getting segmentation fault.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.