lundi 30 mars 2015

Reading input from a text file, converting into int, and storing into array.


Vote count:

0




I need some help. I have a text file that looks like so:


21,M,S,1

22,F,M,2

19,F,S,3

65,F,M,4

66,M,M,4


What I need to do is put the first column into an array int[] age and the last column into an array int[] districts. This is for a college project due in a week. I've been having a lot of trouble trying to figure this out. Any help would be greatly appreciated. I did try searching for an answer already but didn't find anything that i understood. I also cannot use anything we havent learned from the book, so it rules out lists<> and things of the like.



FileStream census = new FileStream("census.txt", FileMode.Open, FileAccess.Read);
StreamReader inFile = new StreamReader(census);
string input = "";

string[] fields;
int[] districts = new int[SIZE];
int[] ageGroups = new int[SIZE];

input = inFile.ReadLine();

while (input != null)
{
fields = input.Split(',');


for (int i = 0; i < 1; i++)
{
int x = int.Parse(fields[i]);

districts[i] = x;

}
input = inFile.ReadLine();


}
Console.WriteLine(districts[0]);


asked 29 secs ago







Reading input from a text file, converting into int, and storing into array.

Aucun commentaire:

Enregistrer un commentaire