Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Name: Tyler Neath

Short Assignment #11

1. Suppose the following declarations are in effect:


int a[] = {5, 15, -1, 10, 4, 8, 74, 11};
int *p, *q;
p = &a[1];
q = &a[5];
(a) What is the value of *(p+3)?
4
(b) What is the value of *(q-3)?
-1
(c) What is the value of q-p on a system where integers are
stored using 4 bytes?
4
(d) Is the condition p<q true or false?
true
(e) Is the condition *p < *q true or false?
false

2. Modify Problem 3 of your Short Assignment #10 so as to allow


the user to enter the file name of the file to be read. Be sure
to check that the file exists when trying to open it. Also add
functionality to your program that sorts the array in ascending
order and writes the sorted data to another file, determined
again by the user.

#include <stdio.h>
#include <sting.h>
int main(void) {
FILE *file;
FILE *file2;
int N;
int i;
int num;
char filestring[];
printf("What file would you like to be read?\n\n");
scanf("%s",filestring[]);

file = fopen(filestring, "r");

if (file == NULL) {
printf("File not found!! Exiting.\n");
}

int done = 0;
while (!done) {

int message = fscanf(file , "%d", &num);

if (message == EOF)
done = 1;
else {
N++;
}
}

fclose(file);

int array[600];
file2 = fopen(filestring, "r");

for (i=0;i<N;i++) {
fscanf(file2 , "%d", &num);
array[i]= num;
}

fclose(file2);

int MIN,MAX;

for (i=0;i<N-1;i++) {
if (array[i] < array[i+1])
MIN = array[i];
else if (array [i] > array[i+1])
MAX = array[i];
}
return(0);
}

You might also like