Thread: New programmer here!

  1. #16
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    sizeof(char) is 1:
    Code:
    char *foo = malloc(size);

  2. #17
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    char *f = malloc(1);

  3. #18
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Yes, if you wanted to only malloc one char. My example is for allocation of size chars.

  4. #19
    Linux User
    Join Date
    Nov 2005
    Location
    Bellingham, WA
    Posts
    35
    My bad it should have been
    Code:
    char* storage = malloc(sizeof(char) * size+1);
    I forgot the parenthesis at the very end. Anyway this should fix the syntax error;
    "Just as eating contrary to the inclination is injurious to the health,
    so study without desire spoils the memory, and it retains nothing that it takes in."


    - Leonardo De Vinci (1452-1519)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What game programmer should I be? need some advice.
    By m3rk in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-20-2009, 11:12 PM
  2. When are you REALLY a programmer?
    By m.mixon in forum C Programming
    Replies: 5
    Last Post: 07-19-2006, 09:08 PM
  3. Senior 3D Programmer - Moab Studios™ LLC
    By moab in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 08-30-2005, 10:19 PM
  4. Me as a programmer?
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-31-2002, 06:19 PM
  5. I need to interview professional programmer.....please
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2002, 02:46 PM