return the file contents into an array or string

J

jmazzi

Hey everyone,

Im looking to write a program that will read the file contents of a
file into an array to use later. Ive searched through this list and
seem to only find over bloated programs that do that. Heres a simpe
example of what im talking about:



int main() {
char *conf;

conf = read_config();
printf("%s\n", conf);
return 0;
}

char * read_config(char *filename) {

..........

}


can anyone point me in the right direction?

Thanks!
 
U

Uncle_Jed

Im looking to write a program that will read the file contents of a
file into an array to use later. Ive searched through this list and
seem to only find over bloated programs that do that. Heres a simpe

How you do this is going to depend on the file format and layout. Will
you be using a binary file or text file? In either case you need to
define a record (logical unit of storage).

Many of the available C text books cover this topic in detail. I suggest
you obtain one a.s.a.p.

-R
 
M

Mark McIntyre

Hey everyone,

Im looking to write a program that will read the file contents of a
file into an array to use later.

Why not fgets each line of your config file into an array of strings.
and then strncmp each one to your target config option, when using
them. Not very elegant but simple.
Ive searched through this list

This isn't a list, its a usenet group.
Mark McIntyre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top