Commit 72bc16c5 by shtaya

lab1hw.c file reading completed

parent b27a0120
Showing with 59 additions and 0 deletions
/*
Lab I HW1
file - http://innar.com/similarity/data.txt
So, the first week's task is to read in the file and out the read in values into arrays.
Structure is as follows - person_id,book_id
Each represents an unique identificator number to differentiate. The data shows who bought what book.
After the data has been read in, find the following info and connections from the provided data:
1. How many people bought book x.
2. How many bought bought both x and y together.
3. Cross-table of different books for each possible combination.
4. Calculate the odds for the book buying. (Use the result from 3. and divide by count of the book bought)
*/
#include <stdio.h>
#include <stdlib.h>
#define NFIELD 908576
#define FNAME "data.txt"
typedef struct sales
{
int person_id;
int book_id;
} sales_t;
void readFile(sales_t *);
int main(void)
{
sales_t data[NFIELD];
readFile(data);
return 0;
}
void readFile(sales_t *sp)
{
FILE *fp;
char s[20];
int i;
fp = fopen(FNAME,"r");
if (fp == NULL)
{
printf("file cannot be opened\n");
}
fscanf(fp, "%s\n", s);
for(i = 0; i < NFIELD; i++)
{
fscanf(fp, "%d,%d\n", &(sp+i)->person_id,&(sp+i)->book_id);
}
fclose(fp);
return;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment