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

  • Home
  • SEARCH
  • 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 6663717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:31:47+00:00 2026-05-26T02:31:47+00:00

I am trying to create a structure that can be dynamically added to with

  • 0

I am trying to create a structure that can be dynamically added to with malloc and free. There are three functions that I need to implement. I need to be able to print the current structure and move to the next structure and print it as well (Needs to loop through and print each struct).

This part give me an error that goes as follow:

No more issues occured look at what I edited. I cannot submit my own answers

Employee.c:27: warning: assignment makes integer from pointer without a cast

Line is printf(\n The Employee's name is:%s, employee->fullName);

Employee.c:29: warning: assignment makes integer from pointer without a cast
printf("\nThe Employee started on %s", employee->startdate);

Here’s some of my source:

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

/// PRINT RECORDS ///
void printRecords(myEmployee * emp)
{
    myEmployee *employee;
    for (employee = emp; employee != NULL; employee = employee->next) {

        printf("\nThe Employee's Name is: %s", employee->fullName);
        printf("\nThe Employee makes is a year $ %f", employee->salary);

        printf("\nThe Employee started on %s", employee->startdate);
        printf("\n\nThe Next Employee:\n");
    }

}

//// CREATERECORD ////
myEmployee *createRecord(char *fullname, char *date, float sal)
{
    myEmployee *newEmployees = malloc(sizeof(myEmployee));
    if (newEmployees != NULL) {
        newEmployees->fullName[MAXSIZE] = fullname;
        newEmployees->salary = sal;
        newEmployees->startdate[MAXSIZE] = date;
        newEmployees->next = NULL;
    }
    return newEmployees;
}

These are two of the three functions that I have implemented.

This is the header file that is included:

#include <string.h>
#define MAXSIZE 200

typedef struct employee {
    char *fullName;
    float salary;
    char *startdate;
    struct employee *next;

} myEmployee;

void printRecords(myEmployee * emp);
myEmployee *createRecord(char *fullname, char *date, float sal);
myEmployee *addRecord(char *fullname, char *date, float sal);
void deleteRecord();

Can anyone help point out what is causing the error or what it means when you have a pointer without cast and how to go about making line 32 a compatible pointer type.

Solution:
In the createRecord function is deleted the “[MAXSIZE]” and the code ran with no issues

  • 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-05-26T02:31:48+00:00Added an answer on May 26, 2026 at 2:31 am

    Structures with variable-sized data inside can be tricky. There are two primary tricks; one is to place your variable-length data as the very last member of the struct, and account for its space when you allocate your structures. This works for exactly one variable-length data element. (Well, you can do more complicated tricks, but it surely isn’t worth it most of the time.)

    In your case, your structures are actually a fixed size — which is a good thing — but it does mean that you also have to allocate memory separately for your char pointers:

    myEmployee **createRecord(char *fullname, char *date, float sal)
    {
        myEmployee *newEmployees = malloc(sizeof(myEmployee));
        if (newEmployees != NULL) {
            newEmployees->fullName[MAXSIZE] = fullname;
    

    Your ->fullName pointer is garbage at this point. I don’t know what it points to, but MAXSIZE bytes after, it attempts to store a single character. (Which is where your type error comes from — but fixing it takes much more work than you might guess.)

    Who is in charge of the char *fullname that you have passed into this function? Is it a long-lived piece of memory that you have malloc(3)ed elsewhere? Or was it a stack-allocated variable in whatever function called createRecord()?

    If the variable was stack-allocated (or otherwise intended for a short lifespan), then you need to allocate a place to store a copy:

    myEmployee **createRecord(char *fullname, char *date, float sal)
    {
        myEmployee *newEmployees = calloc(1, sizeof(myEmployee));
        if (newEmployees != NULL) {
            newEmployees->fullName = strdup(fullname);
            /* handle failure how you wish */
            if (!newEmployees->fullName)
                goto fail;
    

    If the variable was allocated with malloc(3) (or otherwise intended for a long lifespan), then you can simply update pointers:

    myEmployee **createRecord(char *fullname, char *date, float sal)
    {
        myEmployee *newEmployees = calloc(1, sizeof(myEmployee));
        if (newEmployees != NULL) {
            newEmployees->fullName = fullname;
    

    So the right answer depends upon how you wish to approach the long-term storage of your objects. Which functions are in charge of allocating and de-allocating the members of your functions? I strongly recommend the first approach — that way, you can write the allocation routine here and the de-allocation routine in destroyRecord() (or whatever the paired function is) and be certain you do not have memory leaks.

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

Sidebar

Related Questions

I need to create a structure inside a function (dynamically with malloc) Then i
Ok, so here's the entire structure I'm trying to create. I need to create
I trying to create grid that contains rows with the following structure: item name,
I'm trying to create an PHP object that can load objects in other files
I'm trying to create a JAR that I can put on a non development
I am trying to create a modular structure that will eventually live inside another
I am trying to figure out how to create a java program that can
I'm trying to create a structure that will will be iterated across and the
I am trying to create a tree structure (a binary tree) that is capable
I'm new to database structure. I'm trying to create an app that allows users

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.