Answer to Question #7880 in C++ for Jun Park

Question #7880
Month Year Open High Low Close Avg Vol December 2008 91.3 103.6 84.55 85.35 33800900 November 2008 105.93 111.79 79.14 92.67 44957200 October 2008 111.92 116.4 85 107.59 66902300 September 2008 172.4 173.5 100.59 113.66 43697600 August 2008 159.9 180.45 152.91 169.53 23273800 July 2008 164.23 180.91 146.53 158.95 33096200 June 2008 188.6 189.95 164.15 167.44 34281100 May 2008 174.96 192.24 172 188.75 32650300 April 2008 146.3 180 143.61 173.95 38841700 March 2008 124.44 145.74 118 143.5 42313100 February 2008 136.24 136.59 115.44 125.02 46645400 January 2008 199.27 200.26 126.14 135.36 62108100 In c programming, I have a text file like above but i'm wondering how i can extract only open and close column and store it as two dimension array.
Expert's answer
// Question7880.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include
<stdio.h>
#include <stdlib.h>
#include
<string>
#include <iostream>
FILE *fr;
using namespace
std;
class Dat{
public:
char Month[900];
};

class
Obj{
public:
char Month[900];
};

void
opensafileintfile(){
Dat da[15];
Obj obj[15];
char line[900];
fr =
fopen ("data.txt", "rt"); /* open the file for reading */
fgets(line, 900,
fr);
printf("%s\n", line);
int count=0;
while(fgets(da[count].Month,
900, fr) != NULL)
{
//printf("%s\n", line);
count++;
}

int
c=0;
char line1[10];
float number;
char str[6];
for(int
i=0;i<70;i++){

if(da[0].Month[i]==' ' && da[0].Month[i+1]!='
'){
c++;
if(c==2){
str[0]=da[0].Month[i+1];
str[1]=da[0].Month[i+2];
str[2]=da[0].Month[i+3];
str[3]=da[0].Month[i+4];
str[4]=da[0].Month[i+5];
str[5]=da[0].Month[i+6];


}
}
}
cout<<str;

fclose(fr);
/* close the file prior to exiting the routine */
}
int _tmain(int argc,
_TCHAR* argv[])
{
int
a=0;
opensafileintfile();
scanf("%f",&a);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal