Hey broskis!
I've only taken one class in introductory programming and my internship wants me to organize some excel data (it's in txt now). We never went over files in my c programming class so I'm struggling with this code a bit.
For practicing purposes my text looks like this. (it actually goes on for 330777 more lines).
20010929 0 2
20010929 15 2
20010929 30 2
20010929 45 2
.....
..
.
I'm trying to put this into a 3 by 330777 array. Since I'm a beginner, a 3 by 4 array will suffice.
Soooo basically i want my cout<<data[0][0] to be 20010929 and my cout<<data[3][2] to be 2.
My program thus far is not working out so any help would be greatly appreciated.
#include <stdio.h> /* required for file operations */
#include <dos.h> /* for delay */
#include <iostream>
#include <cstdio>
main(void){
FILE *fr; /* declare the file pointer */
int i;
int data[4][3], x, y;
fr = fopen ("c:\\blahblah.txt", "r"); /* reads the file */
fscanf (fr, "%d", &i);
/*
while (!feof (fr))
{
printf ("%d\n ", i);
fscanf (fr, "%d", &i);
} */
char line[256]; /* array for each line */
for(x=0; x<2; x++){
fgets(line, 256, fr); /* reads each line of the .txt*/
y = 0; /* rows start at zero */
while(sscanf(line,"%d", &data[y++][x])); /* i found this line online so i dont really understand why there is a while and why its not working */
}
fclose(fr); /* close the file prior to exiting the routine */
system("pause");
}