what is the max that will fit in a char
-
I have an array in a struct and I am trying to allocate the correct memory size for the data that I need to put in it. My data is words read from a file. exp: deg active,frozen,stopped ft/sec meters gallon etc...... If I create a char array can I make each one of those an element of the array? sj
-
I have an array in a struct and I am trying to allocate the correct memory size for the data that I need to put in it. My data is words read from a file. exp: deg active,frozen,stopped ft/sec meters gallon etc...... If I create a char array can I make each one of those an element of the array? sj
127 for char 255 for unsigned char [EDIT] You can find this info in limits.h in the include dir of VC++. [/EDIT] John
-
I have an array in a struct and I am trying to allocate the correct memory size for the data that I need to put in it. My data is words read from a file. exp: deg active,frozen,stopped ft/sec meters gallon etc...... If I create a char array can I make each one of those an element of the array? sj
a char is a single byte so the highest value if cast as an integer would be 255 unsigned or 127 signed. It sounds like you are actually asking about the max length of a char array. This would be determined either statically by the defining your array like: // pick a number that is longer than your longest word #define MAX_WORD_LENGTH 20 // if you know how many words you will conceivably have #define MAX_WORDS 100 char words[MAX_WORD_LENGTH][MAX_WORDS]; If this definition is made locally - you'll be limited by the size of your stack. If made globally, you'll be limited by your data segment size - or something like that :) If you don't know how many words you will have or how long they could possibly be then you'll need to pre parse the file and determine how many words there are and how long the longest one is. Then you could use char* buffer; buffer = (char* )malloc(NUM_WORDS*LONGEST_WORD); I'm going to live forever or die trying!