I am writing a program that takes integers from a user and sorts them in ascending order. I understand the process of most of the steps but our teacher has said that the actual function that determines which of two array elements is larger must be done from another .c file.
I'm not quite sure how the calling of another file works. Here is the code I have so far.
p1.c:
Code:
/* This program in its entirety takes a list of integers from a user and arranges them in ascending
order */
#include<stdio.h>
#include "temp.h"
#define PROMPT "Enter up to 10 integers, ending with -1:"
#define TOO_MANY "Exceeded maximum array size."
main(void)
{
char input[MAX_NUM + 1] = {'0'};
int x, i, j, temp1, temp2, temp;
puts(PROMPT);
gets(input);
for(i = 0; i < MAX_NUM; i++)
{
for(j = MAX_NUM; j < i; j--)
{
larger(input[i], input[j]);
if(temp = input[j])
{
temp1 = input[i];
input[i] = input[j];
input[j] = temp1;
}
}
}
return 0;
}
temp.h
Code:
#define MAX_NUM 10
int larger(int a, int b);
temp.c
Code:
#include<stdio.h>
#include "temp.h"
int larger(int a, int b)
{
if(a > b)
{
temp = a;
} else temp = b;
return temp;
}
The teacher provided us with the temp.h and says that the larger() function must be defined in temp.c. So now that I have that, how do I access the function from p1.c?
And will the 'temp' variable returned in the larger() function be accessible from p1.c in the manner I've written?