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 7783769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:56:11+00:00 2026-06-01T19:56:11+00:00

I’m using Visual Studio 2010, which I know has some idiosyncrasies. I’m hoping it’s

  • 0

I’m using Visual Studio 2010, which I know has some idiosyncrasies. I’m hoping it’s not that.

This is obviously part of a bigger program, but I’ve tried to simplify it so I could figure out what I’m doing.

Every time I run it, the calloc assignment resolves as NULL and I exit out of the program. I tried it without the if statement around calloc, and got a debug error, so I’m pretty sure it’s calloc that is the issue.

Any help would be appreciated.

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

typedef struct NODE {
    char * x;
    struct NODE * link;
} NODE;

typedef struct {
    NODE * first;
} STRUCTURE;

NODE * insertNode (NODE * pList, NODE * pPre, char * string);

int main (void) {
   STRUCTURE  str[2];
   char * string = "blah";
    str[2].first = NULL;
    str[2].first = insertNode (str[2].first, str[2].first, string); 
    printf ("\n%s\n", str[2].first->x);
return 0;
}

NODE * insertNode (NODE * pList, NODE * pPre, char * string)
{
    //Local Declarations
    NODE * pNew;

    //Statements
    if ( !(pNew = (NODE*)malloc(sizeof(NODE)))) 
            printf ("\nMemory overflow in insert\n"),
                exit (100);
        if ( ( pNew->x = (char*)calloc((strlen(string) + 1), sizeof(char))) ==     NULL);
        {
            printf ("\nMemory overflow in string creation\n");
            exit (100);
        }
        strncpy(pNew->x, string, strlen(pNew->x)); 
    if (pPre == NULL) //first node in list
    {
        pNew->link = pList;
        pList = pNew;
    }
    else 
    {
        pNew->link = pPre->link;
        pPre->link = pNew;
    }

    return pList;
}
  • 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-01T19:56:12+00:00Added an answer on June 1, 2026 at 7:56 pm

    I’m using Visual Studio 2010, which I know has some idiosyncrasies. I’m hoping it’s not that.

    It’s a semicolon:

    if ( ( pNew->x = (char*)calloc((strlen(string) + 1), sizeof(char))) ==     NULL);
                                                                                    ^
    

    No matter what calloc returns, the following block will be entered and you’ll call exit.


    Side note, you could write it like this:

    if (!(pNew->x = calloc(strlen(string) + 1, 1)))
        /* ... */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.