Question

Need C programming help. I've started to work on the program, however I struggle when using...

Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LINE 100
#define MAX_NAME 30

int countLinesInFile(FILE* fPtr);
int findPlayerByName(char** names, char* target, int size);
int findMVP(int* goals, int* assists, int size);
void printPlayers(int* goals, int* assists, char** names, int size);
void allocateMemory(int** goals, int** assists, char*** names, int size);
void sortPlayersByGoals(int* goals, int* assists, char** names, int size);
void writeToFile(FILE* fPtr, int* goals, int* assists, char** names, int size);
void readLinesFromFile(FILE* fPtr, int* goals, int* assists, char** names, int numLines);

// Bonus function
void bonusSortPlayersByBoth(int* goals, int* assists, char** names, int size);

// Main function receives two command line arguments. The first is the name
// of the input file; the second is the name of the output file. If either one
// is missing, or the input file cannot be opened, the program should print an
// error message and end.
//
// You are responsible for making the output of your program match the sample
// output. That means you must determine the appropriate algorithm on your own;
// TAs will not provide a step-by-step list of functions to call, or how to
// achieve the proper output. It is recommended that you implement main after
// implementing some of the other functions; this may help you to see the purpose
// of main more clearly.
int main(int argc, char** argv)
{
        
}

// Counts how many lines are in the file provided. After counting,
// this function should rewind the file for future use.
//
// INPUT: fPtr - A pointer to a file opened in read mode.
// RETURNS: The number of lines in the file.
int countLinesInFile(FILE* fPtr)
{

}

// Finds a player by their name.
//
// INPUT: names  - A pointer to the strings containing the player names.
//        target - The name of the player to find.
//        size   - The number of players to search through.
// RETURNS: The index of the player if found; -1 otherwise.
int findPlayerByName(char** names, char* target, int size)
{

}

// Finds the most valuable player (MVP) of the players. (The MVP has the greatest goals + assists total.)
//
// INPUT: goals   - An array containing the number of goals scored per player.
//        assists - An array containing the number of assists per player.
//        size    - The number of players in each array.
// RETURNS: The index of the MVP. You may assume that size > 0 and therefore, there will always be
//          an MVP. In the event of a tie, you may return any of the players in the tie.
int findMVP(int* goals, int* assists, int size)
{

}

// Prints the players names along with their goals and assists.
// YOU MUST USE FORMATTED OUTPUT IN THIS FUNCTION. Failing to do so
// will result in a loss of half of the points for this function.
// Players should be printed out as follows:
//
// Name          Goals   Assists
// Backes        4       2
// Pietrangelo   3       1
//
// You must include the column headers in your output. THIS FUNCTION,
// AND MAIN, SHOULD BE THE ONLY OUTPUT-PRODUCING FUNCTIONS IN YOUR PROGRAM.
// If other functions produce output, you will lose half of the points for
// those functions. It is very important not to produce errant output!
//
// INPUT: goals   - An array containing the number of goals per player.
//        assists - An array containing the number of assists per player.
//        names   - An array containing the names of each player.
//        size    - The number of players in each array.
void printPlayers(int* goals, int* assists, char** names, int size)
{

}

// Allocates memory for the player names, their goals, and their assists.
// HINT: Allocating the memory for the goals and assists is straightforward;
// allocating memory for the names is going to be very similar to lab 2, with
// an extra dereference to account for the fact that we are using a char***.
//
// INPUT: goals   - A pointer to a variable which should contain the malloced memory for goals.
//        assists - A pointer to a variable which should contain the malloced memory for assists.
//        names   - A pointer to a variable which should contain the malloced memory for names.
//        size    - The number of players to malloc memory for.
void allocateMemory(int** goals, int** assists, char*** names, int size)
{

}

// Sorts the players according to the number of goals they've scored, in descending order.
// You must use insertion sort or selection sort for this function.
// USE OF ANY OTHER SORTING FUNCTION WILL RESULT IN NO POINTS FOR THIS FUNCTION.
// Keep in mind that moving an entry in one array will require you to
// move entries in the other two arrays, to keep player information synchronized.
// (There are a few ways to accomplish this with names, some easier than others.)
//
// INPUT: goals   - An array containing the number of goals per player.
//        assists - An array containing the number of assists per player.
//        names   - An array containing the names of each player.
//        size    - The number of players in each array.
void sortPlayersByGoals(int* goals, int* assists, char** names, int size)
{

}

// Writes the player information to the given file, in the same order as the input file.
// You should not call this function until after you have sorted the player information,
// so that the information appears in sorted order in the output file.
//
// INPUT: fPtr    - A pointer to a file to write to.
//        goals   - An array containing the number of goals per player.
//        assists - An array containing the number of assists per player.
//        names   - An array containing the names of each player.
//        size    - The number of players in each array.
void writeToFile(FILE* fPtr, int* goals, int* assists, char** names, int size)
{

}

// Reads the player information from the given file. Information is in the following format:
// 
// [name] [goals] [assists]
// Backes 1 5
// Pietrangelo 2 7
//
// YOU MAY NOT USE FSCANF IN THIS FUNCTION! Doing so will result in no points. Instead you
// must use fgets in combination with the strtok function in order to break the line into
// pieces. You can read about strtok online or in your textbook; email your TA with any
// questions.
//
// INPUT: fPtr    - A pointer to a file to read from.
//        goals   - An array to be filled with the number of goals per player.
//        assists - An array to be filled with the number of assists per player.
//        names   - An array to be filled with the names of each player.
//        size    - The number of players in each array.
void readLinesFromFile(FILE* fPtr, int* goals, int* assists, char** names, int numLines)
{

}

// BONUS FUNCTION - worth 5 extra points. You may only receive points for the bonus
// if you have implemented all other functions with no major flaws. This is up to the
// discretion of your TA.
//
// This function sorts the players according to two fields - goals and assists.
// Players should be sorted according to their goals scored first, then they will
// be sorted by the number of assists they have scored as a second criteria. Example:
//
// Tarasenko 5 5
// Berglund 5 2
// Pietrangelo 2 7
// Perron 2 6
// McDonald 2 4
// Redden 2 0
// Backes 1 5
// 
// Note that within each grouping of players with the same number of goals,
// they are subsequently sorted by the number of assists. If two players have
// the same number in each category, you may place them in any order.
//
// Unlike the other sort function, you may use any type of sort algorithm to
// implement this function. Note that this does not excuse you from implementing
// the other sort function with the proper algorithm. It will probably be easiest
// to simply call the other sort function from within this one, and then perform
// the sub-sort afterwards.
void bonusSortPlayersByBoth(int* goals, int* assists, char** names, int size)
{

}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LINE 100
#define MAX_NAME 30

int countLinesInFile(FILE* fPtr);
int findPlayerByName(char** names, char* target, int size);
int findMVP(int* goals, int* assists, int size);
void printPlayers(int* goals, int* assists, char** names, int size);
void allocateMemory(int** goals, int** assists, char*** names, int size);
void sortPlayersByGoals(int* goals, int* assists, char** names, int size);
void writeToFile(FILE* fPtr, int* goals, int* assists, char** names, int size);
void readLinesFromFile(FILE* fPtr, int* goals, int* assists, char** names, int numLines);

// Bonus function
void bonusSortPlayersByBoth(int* goals, int* assists, char** names, int size);

// Main function receives two command line arguments. The first is the name
// of the input file; the second is the name of the output file. If either one
// is missing, or the input file cannot be opened, the program should print an
// error message and end.
//
// You are responsible for making the output of your program match the sample
// output. That means you must determine the appropriate algorithm on your own;
// TAs will not provide a step-by-step list of functions to call, or how to
// achieve the proper output. It is recommended that you implement main after
// implementing some of the other functions; this may help you to see the purpose
// of main more clearly.
int main(int argc, char** argv)
{
      
}

// Counts how many lines are in the file provided. After counting,
// this function should rewind the file for future use.
//
// INPUT: fPtr - A pointer to a file opened in read mode.
// RETURNS: The number of lines in the file.
int countLinesInFile(FILE* fPtr)
{

}

// Finds a player by their name.
//
// INPUT: names - A pointer to the strings containing the player names.
//        target - The name of the player to find.
//        size   - The number of players to search through.
// RETURNS: The index of the player if found; -1 otherwise.
int findPlayerByName(char** names, char* target, int size)
{

}

// Finds the most valuable player (MVP) of the players. (The MVP has the greatest goals + assists total.)
//
// INPUT: goals   - An array containing the number of goals scored per player.
//        assists - An array containing the number of assists per player.
//        size    - The number of players in each array.
// RETURNS: The index of the MVP. You may assume that size > 0 and therefore, there will always be
//          an MVP. In the event of a tie, you may return any of the players in the tie.
int findMVP(int* goals, int* assists, int size)
{

}

// Prints the players names along with their goals and assists.
// YOU MUST USE FORMATTED OUTPUT IN THIS FUNCTION. Failing to do so
// will result in a loss of half of the points for this function.
// Players should be printed out as follows:
//
// Name          Goals   Assists
// Backes        4       2
// Pietrangelo   3       1
//
// You must include the column headers in your output. THIS FUNCTION,
// AND MAIN, SHOULD BE THE ONLY OUTPUT-PRODUCING FUNCTIONS IN YOUR PROGRAM.
// If other functions produce output, you will lose half of the points for
// those functions. It is very important not to produce errant output!
//
// INPUT: goals   - An array containing the number of goals per player.
//        assists - An array containing the number of assists per player.
//        names   - An array containing the names of each player.
//        size    - The number of players in each array.
void printPlayers(int* goals, int* assists, char** names, int size)
{

}

// Allocates memory for the player names, their goals, and their assists.
// HINT: Allocating the memory for the goals and assists is straightforward;
// allocating memory for the names is going to be very similar to lab 2, with
// an extra dereference to account for the fact that we are using a char***.
//
// INPUT: goals   - A pointer to a variable which should contain the malloced memory for goals.
//        assists - A pointer to a variable which should contain the malloced memory for assists.
//        names   - A pointer to a variable which should contain the malloced memory for names.
//        size    - The number of players to malloc memory for.
void allocateMemory(int** goals, int** assists, char*** names, int size)
{

}

// Sorts the players according to the number of goals they've scored, in descending order.
// You must use insertion sort or selection sort for this function.
// USE OF ANY OTHER SORTING FUNCTION WILL RESULT IN NO POINTS FOR THIS FUNCTION.
// Keep in mind that moving an entry in one array will require you to
// move entries in the other two arrays, to keep player information synchronized.
// (There are a few ways to accomplish this with names, some easier than others.)
//
// INPUT: goals   - An array containing the number of goals per player.
//        assists - An array containing the number of assists per player.
//        names   - An array containing the names of each player.
//        size    - The number of players in each array.
void sortPlayersByGoals(int* goals, int* assists, char** names, int size)
{

}

// Writes the player information to the given file, in the same order as the input file.
// You should not call this function until after you have sorted the player information,
// so that the information appears in sorted order in the output file.
//
// INPUT: fPtr    - A pointer to a file to write to.
//        goals   - An array containing the number of goals per player.
//        assists - An array containing the number of assists per player.
//        names   - An array containing the names of each player.
//        size    - The number of players in each array.
void writeToFile(FILE* fPtr, int* goals, int* assists, char** names, int size)
{

}

// Reads the player information from the given file. Information is in the following format:
//
// [name] [goals] [assists]
// Backes 1 5
// Pietrangelo 2 7
//
// YOU MAY NOT USE FSCANF IN THIS FUNCTION! Doing so will result in no points. Instead you
// must use fgets in combination with the strtok function in order to break the line into
// pieces. You can read about strtok online or in your textbook; email your TA with any
// questions.
//
// INPUT: fPtr    - A pointer to a file to read from.
//        goals   - An array to be filled with the number of goals per player.
//        assists - An array to be filled with the number of assists per player.
//        names   - An array to be filled with the names of each player.
//        size    - The number of players in each array.
void readLinesFromFile(FILE* fPtr, int* goals, int* assists, char** names, int numLines)
{

}

// BONUS FUNCTION - worth 5 extra points. You may only receive points for the bonus
// if you have implemented all other functions with no major flaws. This is up to the
// discretion of your TA.
//
// This function sorts the players according to two fields - goals and assists.
// Players should be sorted according to their goals scored first, then they will
// be sorted by the number of assists they have scored as a second criteria. Example:
//
// Tarasenko 5 5
// Berglund 5 2
// Pietrangelo 2 7
// Perron 2 6
// McDonald 2 4
// Redden 2 0
// Backes 1 5
//
// Note that within each grouping of players with the same number of goals,
// they are subsequently sorted by the number of assists. If two players have
// the same number in each category, you may place them in any order.
//
// Unlike the other sort function, you may use any type of sort algorithm to
// implement this function. Note that this does not excuse you from implementing
// the other sort function with the proper algorithm. It will probably be easiest
// to simply call the other sort function from within this one, and then perform
// the sub-sort afterwards.
void bonusSortPlayersByBoth(int* goals, int* assists, char** names, int size)
{

}

Add a comment
Know the answer?
Add Answer to:
Need C programming help. I've started to work on the program, however I struggle when using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • CAN YOU SOLVE THIS WITH EXPLANATION? The first part of your program will read some player...

    CAN YOU SOLVE THIS WITH EXPLANATION? The first part of your program will read some player information from a file, format the information, put it into an array of structures, and then display that array on the screen. You will find the following structure useful: The input for your program is in a file called players.txt. Each record in the file represents one player and is made up of multiple fields that are separated by colons. The fields for each...

  • need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data...

    need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data file – It has: player ID, player first name, middle initial, last name soccer.txt – Player information file – It has: player ID, goals scored, number of penalties, jersey number output file - formatted according to the example provided later in this assignment a) Define a struct to hold the information for a person storing first name, middle initial, and   last name). b) Define...

  • C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class...

    C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class called Player that represents a player in the National Hockey League. Player class Use the following class definition: class Player { public: Player(); Player( const char [], int, int, int ); void printPlayer(); void setName( const char [] ); void setNumber( int ); void changeGoals( int ); void changeAssists( int ); int getNumber(); int getGoals(); int getAssists(); private: char name[50]; int number; int goals;...

  • (C++ programming) Need help with homework. Write a program that can be used to gather statistical...

    (C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...

  • C programming The program will require the following structure: struct _data { char *name; long number;...

    C programming The program will require the following structure: struct _data { char *name; long number; }; The program will require command line arguments: int main(int argv, char **argc) { Where argv is the number of arguments and argc is an array holding the arguments (each is a string). Your program must catch any case where no command line arguement was provided and print a warning message (see below). You MUST include/use the following functions, defined as follows: int SCAN(FILE...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • IN C ONLY As mentioned earlier there are two changes we are going to make from...

    IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...

  • Code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; ...

    code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; Specification: In this lab, five functions need to be implemented using the given ADT. 1. Employee* readRecord(FILE*) This function receives a FILE pointer created before. It reads a line from the provided csv file, and creates an Employee struct pointer with the information from that line then returns the pointer back to the calling function. Each line in the provided csv file contains the id, salary,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT