iBuy data structures
Functions to read and write iBuy data from files
 All Data Structures Files Functions
ibuy_io.c File Reference

iBuy File input and output functions implementation More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "structures.h"
#include "ibuy_io.h"

Functions

int readUsersFromFile (char inputFile[], struct User users[], int *nUsers)
 Read data from a file to initialize User structures. More...
 
int writeUsersToFile (char outputFile[], struct User users[], int nUsers)
 
int readItemsFromFile (char inputFile[], struct Item items[], int *nItems)
 
int writeItemsToFile (char outputFile[], struct Item items[], int nItems)
 
int parseIntSeq (char *token, int vector[], int lVector, int *n)
 Internal function to parse a sequence of integer values separated by the ',' character.
 

Detailed Description

iBuy File input and output functions implementation

Author
Juan Gomez Romero
Date
2012-2013

Function Documentation

int readItemsFromFile ( char  inputFile[],
struct Item  items[],
int *  nItems 
)

Read data from a file to initialize Item structures

Parameters
[in]inputFileFile name string
[out]itemsArray of Item structures
[out]nItemsNumber of read items
Returns
0 if success, 1 if error

The function reads a text file line-by-line. The function reads MAX_ITEMS elements at most. Lines have the format: Description;Name;Price;ID_seller;ID_user_voted_Like_1, ..., ID_user_voted_Like_N;ID_user_voted_Deal_1,...,ID_user_voted_Deal_M;ID_user_voted_Sold_1,...,ID_user_voted_Sold_P;

Example: A new brand real flux capacitor;Item1;182.64;2;1,2;3,4;5,6;

int readUsersFromFile ( char  inputFile[],
struct User  users[],
int *  nUsers 
)

Read data from a file to initialize User structures.

Parameters
[in]inputFileFile name string
[out]usersArray of User structures
[out]nUsersNumber of read users
Returns
0 if success, 1 if error

The function reads a text file line-by-line. The administrator user data IS NOT expected to be in the file. The function reads MAX_USERS elements at most. Lines have the format: Login;Password;Name;Surname;Favorite_User_1_UUID,Favorite_User_2_UUID,...;

Example: Lolmar;qwertyui;Lolencio;Martinez;1,4;

int writeItemsToFile ( char  outputFile[],
struct Item  items[],
int  nItems 
)

Write data from Item structures to a file

Parameters
[in]outputFileFile name string
[in]itemsArray of Item structures
[in]nItemsNumber of elements in array items
Returns
0 if success, 1 if error

The function writes item data into a text file line-by-line. Lines have the format: Description;Name;Price;ID_seller;ID_user_voted_Like_1, ..., ID_user_voted_Like_N;ID_user_voted_Deal_1,...,ID_user_voted_Deal_M;ID_user_voted_Sold_1,...,ID_user_voted_Sold_P;

Example: A new brand real flux capacitor;Item1;182.64;2;1,2;3,4;5,6;

int writeUsersToFile ( char  outputFile[],
struct User  users[],
int  nUsers 
)

Write data from User structures to a file

Parameters
[in]outputFileFile name string
[in]usersArray of User structures
[in]nUsersNumber of elements in array users
Returns
0 if success, 1 if error

The function writes users into a text file line-by-line. The administrator user IS NOT printed into the file. Lines have the format: Login;Password;Name;Surname;Favorite_User_1_UUID,Favorite_User_2_UUID,...;

Example: Lolmar;qwertyui;Lolencio;Martinez;1,4;