online-caro.cpp
/*
* Read accounts from the file "account.txt" and write them to a linked-list buffer.
*/
Read accounts from the file "account.txt" and write them to a linked-list buffer.
Read accounts from the file " account . txt " and write them to a linked - list buffer .
void writeAccountsToBuffer() {
	accountDB = (Account*)malloc(sizeof(Account));
	const int MAX_RECORD_LENGTH = 1024;
	char record[MAX_RECORD_LENGTH];
	Account* node = (Account*)malloc(sizeof(Account));
	FILE* file;
	file = fopen(DB_PATH, "r");
	if (!file) printf("[Error]: Could not access the database (this is a test database using file / disable this later - in main() line 238).\n");
	bool isFirstRecord = true;
	Account* account;
	while (fgets(record, MAX_RECORD_LENGTH, file) != NULL) {
		account = (Account*)malloc(sizeof(Account));
		convertRecordToEntity(record, account);
		if (isFirstRecord) {
			node = account;
			isFirstRecord = false;
			accountDB = node;
		}
		else {
			node->next = account;
			node = node->next;
		}
	}
	fclose(file);
}
void writeAccountsToBuffer ( ) { accountDB = ( Account * ) malloc ( sizeof ( Account ) ) ; const int MAX_RECORD_LENGTH = 1024 ; char record [ MAX_RECORD_LENGTH ] ; Account * node = ( Account * ) malloc ( sizeof ( Account ) ) ; FILE * file ; file = fopen ( DB_PATH , " " ) ; if ( ! file ) printf ( " \n " ) ; bool isFirstRecord = true ; Account * account ; while ( fgets ( record , MAX_RECORD_LENGTH , file ) != NULL ) { account = ( Account * ) malloc ( sizeof ( Account ) ) ; convertRecordToEntity ( record , account ) ; if ( isFirstRecord ) { node = account ; isFirstRecord = false ; accountDB = node ; } else { node -> next = account ; node = node -> next ; } } fclose ( file ) ; }
Read accounts from the file "account.txt" and write them to a linked-list buffer.
Read accounts from the file " account . txt " and write them to a linked - list buffer .