Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

generating header files

Name: Anonymous 2010-05-23 11:01

help me /prog/

i need to generate a header file which contains an array with content of a number of files and i also need the lenght of these files in an array.

how should i do that?

Name: Anonymous 2010-05-23 11:03

>>1
Read SICP.

Name: Anonymous 2010-05-23 11:06

OK, why are you wanting to read a bunch of files into an array and put that in a header file?

Name: Anonymous 2010-05-23 11:13

This is a pretty straightforward affair.  You read the files, record their path from an assigned root folder and their length, then copy that information into arrays in the header file.  If you do this to a fixed collection of files, you will only need to do this once but make sure those files exist whenever the application is run.

If you mean the files may change in number of content, you choose a reading location and have all data in that directory and subdirectory be assumed as valid until proven otherwise by extension or file header.  You read the files each time at runtime and store their information temporarily.

Name: Anonymous 2010-05-23 12:04

the thing is i dont want to do it at runtime. i want contents of multiple files in one array and their lenght in another one.

Name: Anonymous 2010-05-23 12:31

>>5
As long as the files' contents and the number of files don't change, you should be fine literally writing the contents of them into arrays in the header (hell, if you're going to do that, why not just write all the information in arrays in the header in the first place?).  Just write arrays of strings and an array of whatever type is best for conveying file size.

An alternate approach might be to write this data in binary files and have the header include only the offsets and lengths of each content section so when you want something specific you don't have to search through (multiple) files to get what you want.  Open the known appropriate file, start at position x, and read for y bytes until done, then close.

Name: Anonymous 2010-05-23 13:32

/* files.h */
char file1[] = "\
#include "file1.txt"
";
int HowLongIsFile1 = sizeof(file1);

Name: Anonymous 2010-05-23 13:41

>>7
wow, that is just what i was looking for.
thank you.

thread closed

Name: Anonymous 2010-05-23 14:13

>>8
A shame it won't really work, huh?

And for a real answer to you question, write a Perl script.

Name: Anonymous 2010-05-23 14:14

>>8
Wait, you're telling us you had no clue how to get the size of a file?

Name: Anonymous 2010-05-23 14:17

>>10
i knew that, i just didnt know how to get it into a header/c file.

Name: Anonymous 2010-05-23 14:50

>>11
I'm not surprised that someone who can't even figure out English finds C too challenging.

Name: Anonymous 2010-05-23 15:03

>>12
Hi, Zhivago. I guess we'll be seeing more of you around here.

Name: >12 2010-05-23 15:10

>>13
I don't know who Zhivago is, but if he understands the value of spelling and grammar, I can only welcome him to /prog/.

Name: Anonymous 2010-05-23 17:51

man 3 fseek
man 3 ftell

These functions will help you.

Name: Anonymous 2010-05-23 18:28

>>15
fstat would be rather more useful.

Name: Anonymous 2010-05-24 4:08

>>16
Yeah, that's fine as long as you don't need your code to work on Windows or whatever.

Name: Anonymous 2010-05-24 5:46

>>12
I remember hearing zhivago calling to the hal turner show 3 years ago.

Name: Anonymous 2010-05-24 12:19

>>17
Yeah, that's fine
OMG OPTIMISED
Wondows doesn't use code, silly - only DOTNAT magic!

Name: Anonymous 2010-12-25 22:59

Name: Anonymous 2011-01-31 20:21

<-- check em dubz

Don't change these.
Name: Email:
Entire Thread Thread List