Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Dynamic Arrays: Using malloc() and realloc()

dynamic array realloc malloc array

  • Please log in to reply
41 replies to this topic

#25 Moudi

Moudi

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 131 posts

Posted 10 March 2010 - 10:44 AM

After this epiphany, do you have any descriptions that might be more "newb-accessible"? That is, something that might help the next guy "get it" in fewer rereads? [/curious]


hehe accually i read it once, couldn't understand anything. Went back read more basic tutorials then came back (:
And zekedragon explained a little on msn :)
  • 0

#26 Guest

Guest

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 914 posts
  • Location:USA
  • Programming Language:C, Java, Python, Bash, Others
  • Learning:Assembly, Scheme

Posted 10 March 2010 - 01:07 PM

@n00py: I changed the variable names to prevent confusion. As for the pointer stuff, I have a little note at the beginning that links to the pointer tutorial I did with ZekeDragon.
  • 0
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#27 n00py

n00py

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 10 March 2010 - 09:08 PM

Just now I read your article on pointers. I didn't notice it at first, because the links aren't made obvious on this forum. Perhaps it might be a good idea to give it an underline, and highlight the link (as I should)... I believe your pointer tutorial needs slight modification. It's good, but arrays aren't pointers. There are differences, and the ones that come to mind are described by the points in my previous post. Perhaps it would be best if you worded it like: "Arrays decay to pointer values during runtime."
  • 0

#28 pancho89

pancho89

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 09 April 2010 - 10:55 AM

i just read the post, it's ok, but you have do give more detail, an i think you have an mistake "for (i--;i>=0;i--)".. i don't understand this statement, and furthermore "i" is a local variable in the for, an when the for exits the value of "i" is not holded... Good job anyway, + rep. P.S. sorry for my english but i am romanian
  • 0

#29 Guest

Guest

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 914 posts
  • Location:USA
  • Programming Language:C, Java, Python, Bash, Others
  • Learning:Assembly, Scheme

Posted 09 April 2010 - 11:11 AM

i just read the post, it's ok, but you have do give more detail, an i think you have an mistake "for (i--;i>=0;i--)".. i don't understand this statement, and furthermore "i" is a local variable in the for, an when the for exits the value of "i" is not holded... Good job anyway, + rep. P.S. sorry for my english but i am romanian

What are you talking about? Of course 'i' keeps it's value after the for loop. As long as it's in the same function, 'i' will not change it's value.
Just to prove my point, running this code will print out 10:
#include <stdio.h>

int main(void) {
    int i;
    for (i=0;i<10;i++);
    printf("%d\n", i);
    return 0;
}

  • 0
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#30 pancho89

pancho89

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 09 April 2010 - 11:17 AM

pff... sorry my bad...i thought i was wright...
  • 0

#31 spyder

spyder

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 11 August 2010 - 10:59 AM

Um, I typed in the program, and it compiled fine, but when I enter anything, it only goes to another blank line to infinity.
(Yes I know this is an old tutorial :))
  • 0
I C!(and Python, and C++, and ...)

#32 Guest

Guest

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 914 posts
  • Location:USA
  • Programming Language:C, Java, Python, Bash, Others
  • Learning:Assembly, Scheme

Posted 11 August 2010 - 11:10 AM

Um, I typed in the program, and it compiled fine, but when I enter anything, it only goes to another blank line to infinity.
(Yes I know this is an old tutorial :))

The program should stop reading input when it hits end of file. If you're on Windows, use CTRL+Z on a blank line. On *nix, use CTRL+D on a blank line.
  • 0
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#33 Jarryd

Jarryd

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 63 posts
  • Location:Australia
  • Programming Language:C, Java, C++, C#

Posted 18 October 2010 - 11:34 PM

Nice tutorial mate, easy to read, easy to understand :)
  • 0

#34 Guest

Guest

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 914 posts
  • Location:USA
  • Programming Language:C, Java, Python, Bash, Others
  • Learning:Assembly, Scheme

Posted 25 October 2010 - 07:39 PM

Nice tutorial mate, easy to read, easy to understand :)

Thanks for the compliment; I'm glad you liked it.
  • 0
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#35 Hamzafiaz

Hamzafiaz

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:C
  • Learning:C

Posted 24 October 2012 - 03:23 AM

i typed a program of most simple calulator that h have posted @CCleader . i typed it most correctly but when i compiled it is showing 5 errors and 2 warnings . in which version of C language u made it and give me any suggestion what i can do it now ?
  • 0

#36 Jopach

Jopach

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 23 May 2014 - 03:29 PM

This was just what I needed thanks  :)


  • 0





Also tagged with one or more of these keywords: dynamic array, realloc, malloc, array