yes, that's correct. The number of words is given in the txt file.
I've got it dynamically allocate the strings array, but am having trouble copying the temp variable 'buffer' into the array of strings.
when I add these two lines
into the while loop reading in the text, I get a segmentation fault.Code:strcpy(array[i], buffer); printf("%s\n", array[i]);
oh crap, I think i know what's wrong
brb
edit, nm...that can't be it.
I was thinking the first number in the file was being held in buffer, then being strcpy'd.
but since I did a printf statement of the buffer, it skips the number and prints the first word, so
the buffer is holding the first word, not the number.
Last edited by ktran03; 01-31-2009 at 02:51 PM.
Code:array[0] = "hellohjhjghjgjhgjhghjgjhgj"; array[1] = "world"; printf("%s\n%s\n", array[0], array[1]);
i just tested that after the malloc, so it must be big enough
quick question
how do I know if the file I'm opening is empty?
Why does it matter - if you try to read the file, you will know when you have reached the end. If that is ZERO or 1000 bytes into the file, what difference does it make?
You can measure the length of the file using fseek() and ftell(). But for most things, it doesn't really matter much.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.