Thread: Program crashing b/c of malloc, can someone please help?

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    244

    Program crashing b/c of malloc, can someone please help?

    I created a function to do some security calculations....

    After completing these calculations, this function is suppose to return an array to main.

    I malloc'ed in the function like this... (its a 1d array)
    Code:
       tempResult=malloc(sizeof(int)*(hexLength*4));
       
       return tempResult;

    the functions declaration looks something like this (since im returning a 1d array):
    Code:
    int* NAME (PARAMETERS);
    Oh, and im 'receiving' the array that is returned into main by declaring a 1d integer array as follows:
    Code:
    int *xORresult
    and then setting xORresult array equal to the function call in main...

    Thanks in advance.
    Linklists use recursion to store what? ..... floats!

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There is no way we can tell from that. Try posting the smallest possible compilable example that demonstrates the problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post the smallest and simplest compilable program that demonstrates the problem. At the moment, we cannot check if your code snippet is correct, and then your example function declaration does not really say anything since you chose to replace the parameter list with a bogus PARAMETERS.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program crashing despite no errors and warnings
    By yohanevindra in forum C Programming
    Replies: 10
    Last Post: 09-07-2010, 10:40 PM
  2. Program crashing when replacing newline character
    By mdekom12 in forum C Programming
    Replies: 2
    Last Post: 05-01-2010, 08:49 PM
  3. im a noob at c++, do you think so?
    By belRasho in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2010, 11:02 PM
  4. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  5. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM