C problem (functions)

Dec 6th, 2013
Price: $40 USD

Question description

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


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!

Tutor Answer

(Top Tutor) Daniel C.
School: Carnegie Mellon University

Studypool has helped 1,244,100 students

On Time
Mar 6th, 2017
" Awesome! Exactly what I wanted. "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1820 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors