space efficiency

This is a discussion on space efficiency within the C Programming forums, part of the General Programming Boards category; Hi! I was wondering what the most space efficient way to store strings was? Can you only put them in ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    1

    space efficiency

    Hi!
    I was wondering what the most space efficient way to store strings was? Can you only put them in an array or is there something better?
    Thank-you.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Well, obviously this isn't so efficient:
    char String[1024] = "Hello world!";

    It's a waste of 1011 bytes...

    Instead use:
    char String[] = "Hello world!";

    or:
    char* String = "Hello world!";

    Or use dynamic allocation if you don't know the strings length.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. Calculating space efficiency using sizeof()
    By markcls in forum C Programming
    Replies: 6
    Last Post: 05-19-2007, 05:25 AM
  3. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 12:30 PM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21