C++ Read file in 2D array -


i'm frustrated program. have file contains 100 records but, output not go beyond 17 including header. can tell me doing wrong?

#include "stdafx.h" #include <iostream> #include <fstream>  using namespace std;  char medrecord[100][8]; int header, person;  int main() {      ifstream in("fakedata.txt");     if(!in){         cout << "cannot open file. \n";         return 1;     }  in.read((char *) &medrecord, sizeof medrecord);  for(person = 0; person < 100; person++)      for(header = 0; header < 8; header++) cout << medrecord[person][header] << "";  return 0;  } 

output:

number,gender,givenname,surname,birthday,bloodtype,pounds,feetinches 1,male,joseph,doody,1/10/1968,a-,179.5,5' 7" 2,male,robert,king,8/17/1985,a+,203.1,5' 10" 3,male,richard,murphy,3/18/1944,o+,235.6,6' 1" 4,female,caroline,acosta,5/27/1959,b+,145.4,5' 8" 5,male,john,capps,12/18/1967,o+,186.6,5' 9" 6,female,stephanie,guidry,3/25/1981,o+,177.8,5' 6" 7,female,janet,kimmel,2/23/1977,a+,161.3,5' 7" 8,male,jerrell,wright,8/4/1929,b+,140.6,5' 9" 9,female,cheryl,johnson,12/8/1972,a+,128.7,5' 1" 10,female,sandra,gonzalez,6/1/1974,a+,171.4,5' 9" 11,male,kevin,noel,9/30/1939,o+,212.1,5' 6" 12,female,krysta,booth,7/9/1940,o+,173.1,5' 3" 13,male,sam,clark,7/5/1979,a+,162.4,5' 9" 14,male,james,graves,8/15/1959,a+,235.0,5' 8" 15,male,elton,fink,6/30/1937,a+,198.4,5' 5" 16,male,robert,daniels,10/14/1969,press key continue . . . 

your medrecord array contains 800 characters. outputted text contains 783 characters, 1 line short (or less) of 800. so, sight unseen, you're doing trying read entire file medrecord, , readin or outputting stops when gets filled up.

i counted cutting/pasting open office--if newlines aren't getting counted properly, 783 + 17 = 800 , there go.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -