online-caro.cpp
/*
* Convert record read from the file "account.txt" to the standard entity.
* @param     record     [IN] The record read from the file "account.txt".
* @param     account     [OUT] The standard entity.
*/
Convert record read from the file "account.txt" to the standard entity.
Convert record read from the file " account . txt " to the standard entity .
void convertRecordToEntity(char record[], Account* account) {
	const int FIELD_NUMBER = 3;
	const char delimiter[2] = " ";
	char** buffer = (char**)malloc(FIELD_NUMBER * sizeof(char*));
	int index = 0;
	buffer[index] = strtok(record, delimiter);
	while (buffer[index++] != NULL) {
		buffer[index] = strtok(NULL, delimiter);
	}
	account->username = (char*)malloc(DATA_MAX_SIZE * sizeof(char));
	account->password = (char*)malloc(DATA_MAX_SIZE * sizeof(char));
	strcpy(account->username, buffer[0]);
	strcpy(account->password, buffer[1]);
	account->status = int(buffer[2][0]) - 48; 
	account->next = NULL;
	account->counter = 0; 
}
void convertRecordToEntity ( char record [ ] , Account * account ) { const int FIELD_NUMBER = 3 ; const char delimiter [ 2 ] = " " ; char * * buffer = ( char * * ) malloc ( FIELD_NUMBER * sizeof ( char * ) ) ; int index = 0 ; buffer [ index ] = strtok ( record , delimiter ) ; while ( buffer [ index ++ ] != NULL ) { buffer [ index ] = strtok ( NULL , delimiter ) ; } account -> username = ( char * ) malloc ( DATA_MAX_SIZE * sizeof ( char ) ) ; account -> password = ( char * ) malloc ( DATA_MAX_SIZE * sizeof ( char ) ) ; strcpy ( account -> username , buffer [ 0 ] ) ; strcpy ( account -> password , buffer [ 1 ] ) ; account -> status = int ( buffer [ 2 ] [ 0 ] ) - 48 ; account -> next = NULL ; account -> counter = 0 ; }
Convert record read from the file "account.txt" to the standard entity.
Convert record read from the file " account . txt " to the standard entity .
/* Convert from character to integer. */ /* Default value of all counters. */