• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Hopefully one more question for me for the time being :p

I have to design and create a class that will act as a buffer before outputting to the user. I have to overload the << operator and store the values that were to be displayed in that buffer then do calculations that will count how many characters are to the right of the << and get the arithmetic sum to become the "checkSum". However, I have a problem with overloading<< with int variables. Here's my code:


And the main will consist of:

The line should give a count of 14, I think.

However, the problem I have is that it makes the i1 variable (with the value of 45) back to the ASCII character "-". I know it has to do with the casting of int i to a char but that's the only way I found to change the 'z' back from ASCII value 122 to "z" (and only one character count) and to detect endl characters as only one character.

Anyone know how I can fix this?

A char really is an signed integer, 8 bit in size, with values ranging from -128 to 127. In C (and by extension in C++), a char has no special meaning: it's just a small number.

In the C++ stream library, a char DO have a special meaning:

  1. a "char *" value will be rendered as a string of bytes
  2. a "char" value will be rendered as a single byte

In your code, two things are happening. First, you force an integer value into a char, that you feed to the stream. The stream won't see a number, because to it, a char is special and must be treated as a raw byte. This is why you see a '-' instead of 45, because in ASCII, the character 45 is '-'.

Second, since you don't have an overloaded operator<< for "char", it will use the closest match: the operator<<(int); remember, a char is really just a small integer.

What you should do instead is to add an overload for operator<<(char) and remove the cast in the operator<<(int).
 

usea

Member
Stuck on a few things for my Tank program. How would you build a GameWorld map of 1024x1024x without using arrays or vectors. I already put accesors/mutators in order to call methods from one class to another and is still blank on how to use location classes for my program.
You don't have to explicitly build a world. From your professor's quote you pasted, they want you to just create tanks etc, which have positions. But don't create a huge NxN array to hold every position on the map. Just give tanks (etc) a position. Like, just as a rough example:
Code:
List<WorldObject> worldObjects = new ArrayList<WorldObject>();
Tank t = new Tank(); //tank extends WorldObject (some class with a position)
t.position = new Point(100, 250); //this tank is at position (100, 250)
worldObjects.add(t); //the tank is now in the world
//add tanks, rocks etc in a loop
Your world is defined implicitly by the objects in it, rather than explicitly by defining a location in memory for every possible location in the world.
 

jokkir

Member
A char really is an signed integer, 8 bit in size, with values ranging from -128 to 127. In C (and by extension in C++), a char has no special meaning: it's just a small number.

In the C++ stream library, a char DO have a special meaning:

  1. a "char *" value will be rendered as a string of bytes
  2. a "char" value will be rendered as a single byte

In your code, two things are happening. First, you force an integer value into a char, that you feed to the stream. The stream won't see a number, because to it, a char is special and must be treated as a raw byte. This is why you see a '-' instead of 45, because in ASCII, the character 45 is '-'.

Second, since you don't have an overloaded operator<< for "char", it will use the closest match: the operator<<(int); remember, a char is really just a small integer.

What you should do instead is to add an overload for operator<<(char) and remove the cast in the operator<<(int).

I created a operator overload before that handles char characters :

Code:
MainOutput& MainOutput::operator<<(char* str){	
	count += strlen(str); //Updates value for count
	
	for(int i = 0; i < strlen(str) ; i++){
		checkSum += (int)str[i];
	}
	return *this;
}

The problem is the 'z' is returning the ASCII decimal value when taking it to the buffer. Is this supposed to happen?

Also, the endl when sent to the buffer comes out as an int with a value of 10 (the DEC ASCII value). That's the reason why I cast the int to a char in the beginning when putting the value into the stringstream. But of course it messes up any normal decimal int that gets pushed to the buffer.

I can show you the assignment requirements if you need it.
 
I created a operator overload before that handles char characters :

Code:
MainOutput& MainOutput::operator<<(char* str){	
	count += strlen(str); //Updates value for count
	
	for(int i = 0; i < strlen(str) ; i++){
		checkSum += (int)str[i];
	}
	return *this;
}

The problem is the 'z' is returning the ASCII decimal value when taking it to the buffer. Is this supposed to happen?

Also the endl when sent to the buffer comes out as an int. That's the reason why I cast the int to a char in the beginning when putting the value into the stringstream. But of course it messes up any normal decimal int that gets pushed to the buffer.

I can show you the assignment requirements if you need it.

The single quotes surrounding the 'z' means that it is a character literal (single). This is different from double quotes, like "d1=", which is a pointer to a sequence of bytes terminated by a NULL (0) character.

Single character:
'A' == (char)65

Null terminated string:
"String" == { 'S', 't', 'r', 'i', 'n', 'g', (char)0 };

The "char *" in your class will handle the strings (char *) but not the "char". Since you don't have a operator<<(char), it will be handled instead by the operator<<(int) [1].


1. because char can safely by casted to a integer (no loss of data).


----
Edit: a small example showing the different behavior

Code:
#include <iostream>
#include <cstring>

void overloaded(char *str)
{
	// Got a string
	int length = std::strlen(str);
	std::cout << "Received a string, " << length << " characters long: \"" << str << "\"\n";
}
  

void overloaded(char character)
{
	// Got a byte
	std::cout << "Received a character '" << character << "'\n";
}

void overloaded(int number)
{
	// Got an integer
	std::cout << "Received an integer: " << number << "\n";
}


int main(void)
{
	overloaded("A string");
	overloaded('N');
	overloaded(32767);

	char c = 65;
	char str[] = { 'S', 'e', 'q', 'u', 'e', 'n', 'c', 'e', NULL };

	overloaded(c);
	overloaded((int)c);
	overloaded(str);

	return 0;
}

Outputs:
Received a string, 8 characters long: "A string"
Received a character 'N'
Received an integer: 32767
Received a character 'A'
Received an integer: 65
Received a string, 8 characters long: "Sequence"
 

jokkir

Member
The single quotes surrounding the 'z' means that it is a character literal (single). This is different from double quotes, like "d1=", which is a pointer to a sequence of bytes terminated by a NULL (0) character.

Single character:
'A' == (char)65

Null terminated string:
"String" == { 'S', 't', 'r', 'i', 'n', 'g', (char)0 };

The "char *" in your class will handle the strings (char *) but not the "char". Since you don't have a operator<<(char), it will be handled instead by the operator<<(int) [1].


1. because char can safely by casted to a integer (no loss of data).


----
Edit: a small example showing the different behavior

Code:
#include <iostream>
#include <cstring>

void overloaded(char *str)
{
	// Got a string
	int length = std::strlen(str);
	std::cout << "Received a string, " << length << " characters long: \"" << str << "\"\n";
}
  

void overloaded(char character)
{
	// Got a byte
	std::cout << "Received a character '" << character << "'\n";
}

void overloaded(int number)
{
	// Got an integer
	std::cout << "Received an integer: " << number << "\n";
}


int main(void)
{
	overloaded("A string");
	overloaded('N');
	overloaded(32767);

	char c = 65;
	char str[] = { 'S', 'e', 'q', 'u', 'e', 'n', 'c', 'e', NULL };

	overloaded(c);
	overloaded((int)c);
	overloaded(str);

	return 0;
}

Outputs:
Received a string, 8 characters long: "A string"
Received a character 'N'
Received an integer: 32767
Received a character 'A'
Received an integer: 65
Received a string, 8 characters long: "Sequence"

Awesome. Thank you so much, I think it's working now. Do you know any online resources that cover this? I think it would be good to know for the future
 
Awesome. Thank you so much, I think it's working now. Do you know any online resources that cover this? I think it would be good to know for the future

Not really, sorry. I didn't keep up to date on those things. Hopefully, someone can recommend some good resources.
 
I'm a nerd, because I'm really enjoying my C++ class. It's getting tough, yet I feel triumphant when I solve the problems. Never thought I would like programming. Weird
 

Relix

he's Virgin Tight™
I still don't get the ASP Webforms hate. At least for Enterprise apps (what I build) webforms allows me to quickly build something usable, validate, etc and with excellent performance. I mean, I am not running 25 queries in one page... I try to keep it to the simplest possible as to avoid SQL bottlenecks and also be easy on the webserver. I ran a stress test for a big app I am working on and at least in a Micro EC2 server most of the code performed admirably with the exception of some heavy pages that slowed down the server. Working on optimizing that.

I'll be honest, I don't yet fully grasp the MVC concept. I've tried working on it but decided that instead I'll move from the .NET environment (C# and VB) to PHP/MySQL/Linux environment which gives me another perspective of the programming world and then come back to .NET MVC. I'll get it eventually, I just haven't been put in a position where I need to work with MVC. If the day comes I'll definitely learn it.

As a sidenote, I find PHP a bit... convoluted? Takes some work to get some easy things working. Definitely getting familiarized with it but damn :p. I am struggling. Visual Studio is definitely a fantastic IDE, I got so pampered by it haha.
 
As a sidenote, I find PHP a bit... convoluted? Takes some work to get some easy things working. Definitely getting familiarized with it but damn :p. I am struggling. Visual Studio is definitely a fantastic IDE, I got so pampered by it haha.

I find PHP schizophrenic. Sometimes it wants to act like C. Sometimes it wants to act like a language with a proper exception catching mechanism. Somethings don't follow other languages and are their own random things.
 

Godslay

Banned
I still don't get the ASP Webforms hate. At least for Enterprise apps (what I build) webforms allows me to quickly build something usable, validate, etc and with excellent performance. I mean, I am not running 25 queries in one page... I try to keep it to the simplest possible as to avoid SQL bottlenecks and also be easy on the webserver. I ran a stress test for a big app I am working on and at least in a Micro EC2 server most of the code performed admirably with the exception of some heavy pages that slowed down the server. Working on optimizing that.

I'll be honest, I don't yet fully grasp the MVC concept. I've tried working on it but decided that instead I'll move from the .NET environment (C# and VB) to PHP/MySQL/Linux environment which gives me another perspective of the programming world and then come back to .NET MVC. I'll get it eventually, I just haven't been put in a position where I need to work with MVC. If the day comes I'll definitely learn it.

As a sidenote, I find PHP a bit... convoluted? Takes some work to get some easy things working. Definitely getting familiarized with it but damn :p. I am struggling. Visual Studio is definitely a fantastic IDE, I got so pampered by it haha.

Get a patterns book with actual code in it. It will help you with the MVC pattern as well as many others. Here is an ASP specific one.

http://www.amazon.com/Professional-ASP-NET-Design-Patterns-Millett/dp/0470292784
 

usea

Member
Yeah, as much as I hated on webforms, PHP is much worse. It's like, comically bad.

I just think MVC is better than web forms in every way. I will admit I haven't used asp.net for a number of years, and even then I didn't know it all that well. I'll also admit I don't really care for web development all that much.

The web development I have done, I've liked asp.net mvc. But I'd also be fine doing rails or some go framework (gorilla or revel?). I'd even do node.js before php

I lean toward static typing and functional programming when possible, which is why I've been sticking with C# until I get better at something else. Rust isn't that far away :)

I'm a language snob, though what I'm saying is partially in jest. At the end of the day there are many concerns more important than your favorite language or framework that goes into the decision of what to use. And most shops aren't gonna let you just move your codebase to scala and coffeescript even if it was an effective use of time. The hiring pool goes way, way down among other things.
 

jokkir

Member
I was wondering, how much do software developers make when working in the industry and how does it compared to other jobs like web design, accounting, etc?

My professor was talking about it but he didn't really say how much more or less you get paid doing programming compared to other jobs.

I'll ask this in OT as well
 

leroidys

Member
Then take a look at Joomla, Drupal and the like. They may provide the functionality she's looking for, and one of the standard skins should fit the requirements in terms of markup. Most web hosts these days support them as an automatic install.
I'll give these two a look. Thanks!
 
People here that have experience with separating your program into dlls?
Tips are always welcome. I'm planning on writing an simple game engine that i want to port over next year to the X1 when microsoft releases their SDK for it. And want to start with separate the graphics engine into a dll for an C# editor later on.
 

Onemic

Member
I wanna make a program that checks a SIN number and sees if its valid. Pretty much I need to create a check digit, which is the last number of the SIN that the user input. From there the program is to take the first set of alternatives and add them to themselves, add the individual digits of each of those sums, add the other alternatives in the inputted SIN and create a total. From that total, take the highest integer multiple of 10 and if the difference between that integer and the total is the same as the check digit then it is a valid SIN.

I'm still trying to wrap my brain on how to approach this. Any advice? I have no idea how to make the program take the last digit of an input by a user to create the check digit.

And I can't use array's.
 

Massa

Member
I wanna make a program that checks a SIN number and sees if its valid. Pretty much I need to create a check digit, which is the last number of the SIN that the user input. From there the program is to take the first set of alternatives and add them to themselves, add the individual digits of each of those sums, add the other alternatives in the inputted SIN and create a total. From that total, take the highest integer multiple of 10 and if the difference between that integer and the total is the same as the check digit then it is a valid SIN.

I'm still trying to wrap my brain on how to approach this. Any advice? I have no idea how to make the program take the last digit of an input by a user to create the check digit.

And I can't use array's.

Use the remainder of a division by 10 (n % 10).
 
Practicing arrays and loops in Java. Check out my code that converts Binary into base 10.

Code:
import java.util.Scanner;

public class BinaryConverter {

	public static void main(String[] args) {
		Scanner scnr = new Scanner(System.in);

		// Main program loop
		for (boolean gameRun = true;
				gameRun != false; gameRun = true)
		{
			System.out.print("Please enter a binary code: ");

			// Registers input
			String input = scnr.nextLine();
			char [] code = new char[input.length()];
			Double total = 0.0;
			int power = 2;

			//  Converts string into array of characters
			for (int i = 0; i < input.length(); i++)
			{
				code[i] = input.charAt(i);
			}

			// Converts characters into integer
			for (int i = 0; i < input.length(); i++)
			{
				if (code[i] == '1') 
				{
					int temp = (input.length() - i) - 1;
					Double addition = Math.pow(power, temp);
					total = total + addition;
				}
			}

			// Prints the final integer
			int finalNumber = total.intValue();
			System.out.print("\nFinal number: "
					+ finalNumber + "\n\n");
		}
		
		scnr.close();
	}
}

I know it's not much, but I'm really liking Java.
 

usea

Member
I wanna make a program that checks a SIN number and sees if its valid. Pretty much I need to create a check digit, which is the last number of the SIN that the user input. From there the program is to take the first set of alternatives and add them to themselves, add the individual digits of each of those sums, add the other alternatives in the inputted SIN and create a total. From that total, take the highest integer multiple of 10 and if the difference between that integer and the total is the same as the check digit then it is a valid SIN.

I'm still trying to wrap my brain on how to approach this. Any advice? I have no idea how to make the program take the last digit of an input by a user to create the check digit.

And I can't use array's.
Your description of the process you need to follow is lacking. There's absolutely no way I could understand what you're supposed to do from that description.

Example ambiguities:
What's an "alternative"?
What does it mean to add a set to itself?
You said add the individual digits of "those sums". What are "those sums" and what exactly do you mean by adding individual digits?
What do you mean by the highest integer multiple of 10?

As for checking the last digit of user input, it depends entirely on what language you're using. You didn't mention that. It's an important detail.

All details are important.
 

Onemic

Member
Use the remainder of a division by 10 (n % 10).

Thanks, that was it. Time to slave away.

Your description of the process you need to follow is lacking. There's absolutely no way I could understand what you're supposed to do from that description.

As for checking the last digit of user input, it depends entirely on what language you're using. You didn't mention that. It's an important detail.

All details are important.

Sorry, I'm in class atm, so I was writing in a hurry.
 
Any iOS devs here?

What's the correct way to have a iOS7 and an iOS 6.1 app at the same time? I just rebuilt my app for iOS 7 and theres bugs, and I want to change the design to fit in.

Thanks
 

Exuro

Member
Does anyone have experience with x86 assembly? I think my professor and book have been giving me different answers to finding the size of a stack frame. In my book I believe it shows that the return address to a called functioned is inserted to the caller frame, and then the callee frame starts at a pushed old ebp. My professor is saying the return address is part of the callee frame and so having two different answers kind of sucks when I have an upcoming test and the prof isn't answering my emails :(.

Here's the book example
dX8sZFI.jpg
 

Chris R

Member
Practicing arrays and loops in Java. Check out my code that converts Binary into base 10.

I know it's not much, but I'm really liking Java.

Pretty cool, see if you can do it using only bit shifting and addition. And check out the Java documentation, your method of creating the char array for your string is rather unconventional.
 

Relix

he's Virgin Tight™
I think I am the worst programmer ever.

I am constantly googling code I forgot and stuff like that. I also copy and paste some code from other apps I have created because I also forget them. I suck!

:(

At least I make sure they run very well and follow best practices, and I always validate every data and try doing it the simplest way I can without making it TOO simple or inefficient... but damn I feel bad whenever I have to google a code I used before or something.
 

Zoe

Member
Don't sweat it. Just make sure you're understanding what you're pasting in. Maybe in your comments for the class or snippet, link back to the place where you found it.
 

ominator

Neo Member
I think I am the worst programmer ever.

I am constantly googling code I forgot and stuff like that. I also copy and paste some code from other apps I have created because I also forget them. I suck!

:(

At least I make sure they run very well and follow best practices, and I always validate every data and try doing it the simplest way I can without making it TOO simple or inefficient... but damn I feel bad whenever I have to google a code I used before or something.

my professor said once: a good programmer writes good code. a very good programmer copies good code.

so heads up :)
 

phoenixyz

Member
I also don't see a problem with that. It's no coincidence that there are IDEs and Editors which offer some kind of snippet management.
 

usea

Member
I think I am the worst programmer ever.

I am constantly googling code I forgot and stuff like that. I also copy and paste some code from other apps I have created because I also forget them. I suck!

:(

At least I make sure they run very well and follow best practices, and I always validate every data and try doing it the simplest way I can without making it TOO simple or inefficient... but damn I feel bad whenever I have to google a code I used before or something.
There is a metric that some people have observed (I'm not saying I believe in it). The better a programmer you are, the faster you will hit google when you're stuck or have a problem.
 

Tamanon

Banned
I mean, think of it this way. All those libraries people use, those are just copies of good, useful code. Don't have to re-invent the wheel each time.
 

Yamauchi

Banned
There's nothing wrong with searching for code. The first programmer I ever worked under was a grey beard who had been in the industry for over 30 years. He told me, "Most of the work we do here consists of good, solid copy-and-pastes."
 
Does anyone have experience with x86 assembly? I think my professor and book have been giving me different answers to finding the size of a stack frame. In my book I believe it shows that the return address to a called functioned is inserted to the caller frame, and then the callee frame starts at a pushed old ebp. My professor is saying the return address is part of the callee frame and so having two different answers kind of sucks when I have an upcoming test and the prof isn't answering my emails :(.

Here's the book example

The return address is in the Caller frame, I believe (It's been a while since I've taken it)

[Also I checked and I used the same book. Look at figure 3.21 (I have it on page 220), I think it's a better diagram]
 

Godslay

Banned
I think I am the worst programmer ever.

I am constantly googling code I forgot and stuff like that. I also copy and paste some code from other apps I have created because I also forget them. I suck!

:(

At least I make sure they run very well and follow best practices, and I always validate every data and try doing it the simplest way I can without making it TOO simple or inefficient... but damn I feel bad whenever I have to google a code I used before or something.

I do both as well. Why wouldn't you use the greatest source of information to help you solve a problem? It's silly not to Google.

As far as copying code from other projects, I do it all the time. If you have an existing code base that you wrote, and think that it will work with what you are trying to accomplish, there is nothing wrong with that. It's more efficient.
 
I think I am the worst programmer ever.

I am constantly googling code I forgot and stuff like that. I also copy and paste some code from other apps I have created because I also forget them. I suck!

:(

At least I make sure they run very well and follow best practices, and I always validate every data and try doing it the simplest way I can without making it TOO simple or inefficient... but damn I feel bad whenever I have to google a code I used before or something.

The first step of getting to being a good programmer is accepting that you are an awful programmer because all programmers are awful and all the programming languages are awful. After that and only after that you can write code that is awful in a proper, readable way. Copying code isn't an offense, it's efficiency like Godslay said. The difference between awful and less awful coder is that awful coder copies bad code and less awful copies code made by someone who is also less awful.

edit: frigging spellcheck
 

upandaway

Member
The first step of getting to being a good programmer is accepting that you are an awful programmer because all programmers are awful and all the programming languages are awful. After that and only after that you can write code that is awful in a proper, readable way. Copying code isn't an offense, it's efficiency like Godslay said. The difference between awful and less awful coder is that awful coder copies bad good and less awful copies code made by someone who is also less awful.
Don't freak out it'll be ok
 
Hey Programming-GAF, I figure since I'm now back in CS classes, I'll be joining you all here more often!

Can anyone offer tips on how to get started easily on a program? For reference, I had a horrible 140 (CS 140 being the introductory programming class) professor where I didn't learn too much, and due to a large amount of time between then and getting into another programming class as well as not programming much in between then (which was partially my fault and also the fact that I had other classes so I had less time to work on that) I feel like I'm in over my head with this first assignment, and if anyone could give me some help on a good way to lay out this program and get started, I would be infinitely grateful.
 
Which language? What kind of program?

Java. The program is to take a phrase, and using the number that the position of each letter would correspond to (i.e., since the first word is The, the first three numbers would be 012) take those numbers and be able to decode secret messages from text files.
 
I have my first real interview for entry level (out of college) sofware engineering job and I'm really panicking guys. I've only done one before, for my current internship, but this is just a whole different scale. I hate hardcore technical interviews. Can't I just show what I've done :/ I'm terrified I'm either going to freeze up and fall back to stupid brute force answers instead of clear-minded approaches, or get asked some esoteric thing I just know nothing about. Meh. Can't wait to get this first one put of the way, hopefully it'll at least make me less terrified going forward. Anyone got any advice besides the obvious know your data structures, talk through problems type stuff?
 

phoenixyz

Member
Java. The program is to take a phrase, and using the number that the position of each letter would correspond to (i.e., since the first word is The, the first three numbers would be 012) take those numbers and be able to decode secret messages from text files.
Well, without knowing what exactly your level of knowledge is I would recommend reading the documentation of Java Strings. That will probably help. If you want to know more I would need a bit more information about what your idea how to solve it is and/or what you already have.
 
Well, without knowing what exactly your level of knowledge is I would recommend reading the documentation of Java Strings. That will probably help. If you want to know more I would need a bit more information about what your idea how to solve it is and/or what you already have.

Well, he told us that we'll need to use the charAt() method of String, firstly.

So we have three different files that we have to use, each one has a sentence, and then an assortment of numbers, which you use what position those integers would be in the string from the sentence to decode them into a new message using their correlation with the other numbers we have in the text file. And the final part is showing that it works using a script command in the command line, which I'm not as worried about.

I feel like my biggest problem is just getting started since I haven't done any heavy programming in so long. While I get the ideas behind what I need to do, I just feel a bit stuck when it comes to actually starting it.
 
Hmmm. I need to allocate an array dynamically in c based upon information I read in from a file (first line is number of integers in the file, the rest are the actual numbers). So I use this code (the number of elements and array size calculator are for debugging):

Code:
                fscanf(fileIN,"%i", &(numsize));
 		printf("Number of elements to be read in: %i ints\n", numsize);
 		int sizearr = numsize*sizeof(int);
 		printf("Array size needed to store all ints: %i bytes\n", sizearr);
 		[B]fileArray = malloc(numsize * sizeof(int));[/B]
 		[B]printf("Actual size of Array: %ld bytes\n", sizeof(fileArray))[/B];

But I get

Code:
new-host-2:MergeSort Alex$ mpiexec -n 3 ./ms infile outfile
Reading from file in process 0
Number of elements to be read in: 50 ints
Array size needed to store all ints: 200 bytes
[B]Actual size of Array: 8 bytes[/B]

Why is my array only 4% the actual size I need it to be after calling malloc? The number of elements, 50 * the size of an integer (4 bytes) should malloc to 200, so why isn't it allocating 200 bytes first go?
 

Haly

One day I realized that sadness is just another word for not enough coffee.
You're asking for the size of the fileArray pointer (the head), which is 8 bytes. The operator doesn't know that fileArray is an array.
 
You're asking for the size of the fileArray pointer (the head), which is 8 bytes. The operator doesn't know that fileArray is an array.

But even then the whole array won't be the size I need it to be after malloc'ing it.

Fake edit: It worked? Literally every time I tried to read in all [n] elements (50 in this case) it would only read in the first few...

Now I'm really confused.
 

tokkun

Member
But even then the whole array won't be the size I need it to be after malloc'ing it.

Fake edit: It worked? Literally every time I tried to read in all [n] elements (50 in this case) it would only read in the first few...

Now I'm really confused.

malloc doesn't fail in that manner. If malloc had failed to allocate all the memory you requested, it would return NULL, which would cause a SIGSEGV crash when you dereferenced the array pointer.

The issue is probably not malloc-related.
 
Top Bottom