Share via

calloc crashes program.

Thema 21 Reputation points
2020-10-14T15:46:42.25+00:00

Can someone please tell me why calloc is not working.
The following is a piece of the code. The letter 'A' is
printing but not the letter 'B'.

printf("\nA");

//Prepare variables.
tmpstr4 = (char*)calloc(TMAXSTRINGLENGTH, sizeof(char));
if(tmpstr4 == NULL){
 printf("Error main0000002 - Failed to allocate memory in GetEnvironmentPaths.\n");
 return TMEMALLOCFAILED;
}

printf("\nB");
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments

1 answer

Sort by: Most helpful
  1. David Lowndes 4,731 Reputation points
    2020-10-14T15:50:30.22+00:00

    Presumably your error message is output?
    If so, presumably TMAXSTRINGLENGTH is a very large number?

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.