Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,391 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,137 people online right now. Registration is fast and FREE... Join Now!




reading into array of structure

 
Reply to this topicStart new topic

reading into array of structure

beginnerInC
30 Sep, 2006 - 06:35 AM
Post #1

New D.I.C Head
*

Joined: 28 Sep, 2006
Posts: 8


My Contributions
how can i read a file into an array of structure.??
for example if i have the following file:
bhp.csv which is the following format:
QUOTE

BHP,"27 Aug 2002",9.53,9.56,9.45,9.45,8117955
BHP,"26 Aug 2002",9.45,9.48,9.4,9.48,6990617
BHP,"28 Aug 2002",9.54,9.55,9.4,9.44,12771227
BHP,"29 Aug 2002",9.31,9.31,9.21,9.27,11986227
BHP,"30 Aug 2002",9.21,9.23,9.11,9.11,19340245
BHP,"02 Sep 2002",9.15,9.23,9.05,9.23,8681758
BHP,"03 Sep 2002",9.14,9.25,9.14,9.24,7833427
BHP,"04 Sep 2002",9,9.01,8.88,8.9,18221850
BHP,"05 Sep 2002",8.94,9.03,8.86,8.9,13662050
BHP,"06 Sep 2002",8.8,8.93,8.71,8.88,15374580

how can i read this into an array of structures???

This post has been edited by Dark_Nexus: 1 Oct, 2006 - 02:27 PM
User is offlineProfile CardPM
+Quote Post

Xing
RE: Reading Into Array Of Structure
30 Sep, 2006 - 06:50 AM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
This will give you a start
http://www.cprogramming.com/tutorial/cfileio.html
User is offlineProfile CardPM
+Quote Post

beginnerInC
RE: Reading Into Array Of Structure
30 Sep, 2006 - 04:55 PM
Post #3

New D.I.C Head
*

Joined: 28 Sep, 2006
Posts: 8


My Contributions
i know these things.
what i want to know how to read into an array.
say that i have the follwing:
CODE

#include<stdio.h>
#include<string.h>

typedef struct{
char name[20];
int date;
int third;
int forth;
int fifth;
int sixth;
}stock;


int main(void)
{
FILE* infile;
infile= fopen("bhp.csv","r")
if (infile == NLL)
  printf("Error opening the file!!!\n");

return 0;
}


how i go from here to reading the file into the structure stock??
User is offlineProfile CardPM
+Quote Post

Xing
RE: Reading Into Array Of Structure
30 Sep, 2006 - 07:47 PM
Post #4

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Make use of fscanf and fprintf
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:32AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month