Programming
C problem (functions)

Question Description

I’m trying to learn for my Programming class and I’m stuck. Can you help?

So there are three programs that I need to write. In addition, I need to include two files (as stated below) to store the functions and the output. I will only need the code for the first problem below and the code for the two files.


you will need to create two additional les: header.h containing the declarations for the functions for all three problems and functions.c containing the denitions of the functions you will use for all three problems. Each of your three programs will start with #include "header.h" and will include main and no other functions. Each program will have to be compiled as: gcc file.c functions.c


Here is a body of the header.h file that you will need to use:

// This is your myHeader.h file, you can cut and paste (or copy) it.

// Declarations for sortFile.c

void sort(int array[], int length);

// Declarations for statistics.c

void lowercaseString(char string[]);

void wordStats(FILE *fp, char string[]);

void printFrequencies(FILE *fp);

// Declarations for car-pol.c

void car2pol(double x, double y, double *pr, double *ptheta);

void pol2car(double r, double theta, double *px, double *py);

----

And here is the body for the myfunctions.c that you need to write:

// This is a skeleton for your myFunctions.c file

// Functions for sortFile.c

void sort(int array[], int length) ff enter body gg

// Functions for statistics.c

int letterFrequencies[26]; // Global array for wordStats, printFrequencies

void lowercaseString(char string[]) ff enter body gg

void wordStats(FILE *fp, char string[]) ff

enter body, use letterFrequencies[], use a static variable gg

void printFrequencies(FILE *fp) ff

enter body, use letterFrequencies[] gg

// Functions for car-pol.c

void car2pol(double x, double y, double *pr, double *ptheta) ff enter body gg

void pol2car(double r, double theta, double *px, double *py) ff enter body gg

----

First program:

Write a program sortFile.c that takes as command line arguments an input le

name, an output le name, and an optional third argument indicating the largest number of integers to

sort.

The program opens the input le consisting of at most 50 integers, sorts them in increasing order, and

prints the sorted sequence to the output le. If the optional argument exists, let’s call it k, then if k is

smaller than the number of integers in the input le, only the rst k integers in the input le will be

sorted and printed to the output le. You can assume that the input le exists and has the right format.

(˜)$ more input1

15 -12 2 0

-4 -3 1 2 0

(˜)$ a.out input1 output1.1

(˜)$ more output1.1

-12 -4 -3 0 0 1 2 2 15

(˜)$ a.out input1 output1.2 5

(˜)$ more output1.2

-12 -4 0 2 15

(˜)$ more input2

20 10 20

(˜)$ a.out input2 output2.1

(˜)$ more output2.1

10 20 20

(˜)$ a.out input2 output2.2 10

(˜)$ more output2.2

10 20 20

(˜)$ a.out input2 output2.3 0

(˜)$ more output2.3

(˜)$ more input3

(˜)$ a.out input3 output3

(˜)$ more output3

(˜)$

The program must call the following functions that you will dene in myFunctions.c.

void sort(int array[], int length) – sorts the rst length elements of array

in increasing order. For example, if array is ff7 3 1 2 9gg and length is 3, then sort

will modify array to ff1 3 7 2 9gg. You can assume that length will be at most the size

of array.

The le sortFile.c will consist of only just main dened and functioning as follows.

int main(int argc, char *argv[]) – opens input le argv[1], calls sort to sort

its elements, and prints the sorted elements in the output le argv[2]. If argv[3] exists, then

it is a an integer k. If k is smaller than the number of elements in the input le, then only the rst

k elements will be sorted and printed in the output le.

----


Please send me a message if you need help explaining anything. Thanks!


Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

swat (35)
Rice University

Anonymous
Return customer, been using sp for a good two years now.

Anonymous
Thanks as always for the good work!

Anonymous
Excellent job

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4