Here is my code at the moment, I was just thinking of a way for a while to do this... its quite long, but basically my comments are the things where it explains everything. I'll still be working on this , its fun. Cprogramming tutorials are awesome, but there are still questions that i have, especially about the fscan thingy...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
typedef struct {
char names[50];
int scores[7];
}PEOPLE;
// function declarations
void the_file_name(char *filename);
int how_many_lines(char *filename);
void read_the_file_to_array(char *filename, PEOPLE peoples[], int *size);
void get_the_stats(PEOPLE peoples[], int size);
int main(void) {
char filename[30];
PEOPLE *peoples;
int size;
the_file_name(filename); // Finished the function
peoples = malloc( (how_many_lines(filename)+1) * sizeof(PEOPLE)); // finished this function
read_the_file_to_array(filename, peoples, &size); // NOT FINISHED......I can use this function to put things into arrays
get_the_stats(peoples, size); // NOT FINISHED....Getting the scores..
return EXIT_SUCCESS;
}
/* Function goes through student arrays and prints out the MAX score on each project.
* so in the end, the function will display the person name and print the score and name
* for each assignment, for assignment 1, it will go through that and find the max score and the name
void getStats(PEOPLE peoples[], int size){
// NOT FINISHED
}
/* My xls, cva file looks something like...
* Hammy, Rogers (persons_id) | (what_student_number_they_are_in_class) assignment1 assignment2.. assignment7
* I was thinking something using fscan and returning something as long as its != EOF.
* perhaps putting it into the struct or something.
* maybe something like, where the chars names[50] will hold the names of the students
* and the scores[7], will hold the 7 assignments/projects they did.
* so, each element space will hold a assignment, can i do something like this?
* then pulling the highest number, by using a for loop?
* also, i don't want the persons id nor the number number in class, just need assignments
* hehe, sorry for asking so much
*/
void readFileIntoArray(char *filename, PEOPLE peoples[], int *size){
// NOT FINISHED
}
void the_file_name(char *filename){
int length;
do {
printf("Enter a filename with .xls at the end please. ");
fflush(stdout);
scanf("%s", filename);
length = strlen(filename);
}
while(filename[len-1] != 's' || filename[length-2] != 'l' ||
filename[len-3] != 'x' || filename[length-4] != '.');
//FIINISHED
}
int how_many_lines(char *filename){
FILE *fp;
char a;
int count=0, new_line=0;
fp = fopen(filename, "r");
while(fscanf(fp, "%a", &a) != EOF){
if(a=='\n' && !new_line){
count++;
new_line = 1;
}
else if (a != '\n')
new_line = 0;
}
fclose(fp);
return count;
// FINISHED
}