char string[256];
char string = malloc(sizeof(int) * 256);
So, these are essentially the same thing right?
Type: Posts; User: Alexander
char string[256];
char string = malloc(sizeof(int) * 256);
So, these are essentially the same thing right?
Hey, whatever inspires him to learn, right? :p
Ah ok, so it's really more of a last resort?
Oh jeez, yeah, you're right. I got myself confused. xD I thought he meant to find the sum of all the numbers between 0 and the entered number because that's what he did last chapter. ^^;
Lol well it helped a bunch. It was a great analogy. Thanks. :)
Huh.. Weird.. I think I get it now.. ^^;
Was this pre-written somewhere? Because this odd explanation actually helped a lot for some reason if this is all true. xD
*bookmarks*
So according to that code, I can't just do this?
int* pNums = malloc( sizeof(int) ); /* An array of 1 int. */
pNums[0] = 5;
pNums[1] = 10;
pNums[2] = 666;
So I do have to add the realloc?...
So wait, how can I continue to put more data in that variable then?
So if it's different from int, and double type things, how do I put data into it then? Is it different?
Ah ok. I get most of that. I don't know much about "the heap" I guess then. So it's like higher priority global memory or something?
(lol'd at the double d)
So, it makes a dynamic array type thing? o.o
Well to be honest, I don't really know what the memory the is allocated by malloc and such is used for. I'm that far behind. Do I put variables in it or something? Because isn't that what the "int"...
xD So it's pretty much just ugly coding? Well, I'll try and pretend it doesn't exist then. I don't think I'll need to use it quite yet any ways. Thanks.
Ok, I'm still confused. How do I know when I need to use these functions? Is there any sort of output that will allow me to see what these are doing and such.
Sorry. I'm often a visual learner, so...
I just don't get these at all:
malloc()
free()
realloc()
calloc()
I think I'm having a hard time grasping the point in what these are for.
I'm reading this tutorial by beej. Here.
And I...
Ok, will do. Is there any particular reason? Is it resource consuming or something?
Oooh, I like the goto statement. Is there a drawback to it though?
Hmm, yeah. I didn't want to do that, I know how to do functions, but my tutorial hadn't gotten to them yet, so I thought I'd do it with out that and do it with what they have taught me so far.
Oh! Now I get what you mean!
#include <stdio.h>
int main(void){
int x, z = 0; //variables
while(x>0){ //check user input
Yeah, but then it stops. How should I make the program restart again preferably?
Gah! I'm retarded. I forgot the address part. Sorry. ^^; Thanks for that. And what do you mean by having to enclose the scanf() in a while loop? o.o I didn't know I had to do that. And I want the...
Ok, I'm kind of confused. I swore I understood what I was doing a second ago. xD
I'm trying to learn C and failing apparently. My tutorial gave me this assignment:
So, I thought that it would...