Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
shtaya
/
IAG0582
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
72bc16c5
authored
Feb 08, 2017
by
shtaya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lab1hw.c file reading completed
parent
b27a0120
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
lab_1/lab1hw.c
lab_1/lab1hw.c
View file @
72bc16c5
/*
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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment