Question: At this point you understand how structures work and what they are used for. This time, we are going to concentrate more on the aspects

At this point you understand how structures work and what they are used for. This time, we are
going to concentrate more on the aspects of using strings. The primary complication this time is
that you are going to have to scan in strings that are often too large to be stored in the structures.
You must not attempt to copy more than the maximum characters that can fit into into one of
these fields. In order to do this, you must truncate strings that are any longer than this. It is also
critical that the strings are properly terminated with a NULL character at the end. You'll also have
to limit the size of the strings when searching.
To handle these nuances, you'll use the strncpy() function to copy only as many bytes as are
possible to store and strncmp() to limit how many characters of a string participate in a comparison
operation.
Note: strncpy() does not NULL terminate long strings. You have to do that your-
self!
You are playing a game of Among Us and you want to be able to find imposters. For this homework,
you will implement a way to detect imposters based on the given constraints. You are going to use
a structure that contains a player's information:
username: The gaming handle of the player.
secret: A secret key for the player of a fixed length KEY_LEN.
friends: A list of players given by their gaming handles that the player considers trustworthy
to some level. Note that this is unidirectional.
trust: Level of trust for each friend (player).
The structure is defined as
typedef struct player {
char username [MAX_NAME_LEN] ;
char secret[KEY_LEN] ;
char friends[MAX_FRIENDS][MAX_NAME_LEN] ;
int trust[MAX_FRIENDS] ;
} player_t;
Examine hw6.h carefully. It contains declarations for the global variables, constants, and the
prototypes for the functions you will write.
4 The Assignment
You will write a set of functions that deal with arguments of type player_t. You will modify
occurrences of player_t that exist in a global array of length MAX_PLAYERS called g_player_array
that contains player_t structures. You will keep track of how many structures you have initialized
using a global variable named g_player_count.
4.1 Functions you will write
int read_players(char *in_file);
This function should read a list of players from in_file. The players should be stored in the
g-player_array with the first one stored at offset 0 and so on.
Sometimes, the secret may be larger than the space available to store it in the player_t
structure. In such cases, you should truncate the string appropriately and continue to read
from the file. To facilitate this, you may use a large, temporary buffer to read the string into.
This buffer should be of size MAX_BUFF_LEN.
Empty friends should be stored as an empty string with a trust level of 0. For example, if there
are only 2 friends, the third entry in friends should be an empty string and the third entry in
trust should be 0.
This function should assert that the argument is not NULL. The function should return the num-
ber of players read from the input file. In case an error occurs, it should return an appropriate
error code from the list of error codes in section 4.4 instead.
Don't forget to update g_player_count.
4.2 Input Files
The input file will contain records of the following format:
username$secret$+friend1+friend2..+friendM$+trust1+trust2..+trustN
A player can have [0, MAX_FRIENDS] friends, and each friend is preceeded by a +. Similarly for trust
levels for each friend. Trust levels will be in the same order as the list of friends. Note that the
number of friends and the number of trust levels may be different.
username and each friend is a string, while each trust is an integer.
4.4 Error Codes
NON_READABLE_FILE: The file cannot be opened for read access.
BAD_RECORD: The file is incomplete or does not make sense, data is too big to be stored in the
temporary buffer, usernames are not unique, number of friends and number of trust levels
are different.
TOO_MUCH_DATA: The file contained more than MAX_PLAYERS.
NOT_FOUND: A player cannot be found in g-player_array.
NO_PLAYERS: The file does not have any players, or there are no players in g-player_array.
These Standard Rules Apply
You may add any #includes you need to the top of your hw6.c file.
You may not create any global variables other than those that are provided for you. Creation
of additional global variables will impact your style grade.
You should check for any failures and return an appropriate value.
You should not assume any maximum size for the input files. The test program will generate
files of arbitrary size.
Do not put multiple conditions inside of assert statements.
Please write the function keeping into account the fact that there will be a random amount of friends with trust (including 0). you also have to catch if theres more than max_friends in the file input line and throw an error if that's the case. please don't just use ai, i've obviously tried that, i need help
 At this point you understand how structures work and what they

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!