dimanche 19 avril 2015

What is the proper way to call multiple functions in C?

I am trying to write a program that will accept some integers and sort them, then display the list in ascending order. It will then check for adjacent triplets and display how many adjacent triplets there are.


The issue is that only the input function is being executed in main.


Could it be that the other functions should be voids? What is the "proper" way to call multiple functions in C?



#include <stdio.h>
int main()
{
input();
sort();
comparator();
output();
getchar();
getchar();
return 0;
}
int input()
{
int n, i, array1[30];
printf("Input the number of integers: ");
scanf("%d", &n, "\n");
printf("Input the integers: ");
for (i = 0; i = n; i++)
scanf("%d", &array1[i]);
return 0;
}
int sort(n, i, array1)
{
int a, b, *arrayS;
arrayS = &array1;
for (i = 1 ; i <= n - 1; i++)
a = i;
while ( a > 0 && arrayS[a] < arrayS[a-1])
b = arrayS[a];
arrayS[a] = arrayS[a-1];
arrayS[a-1] = b;
a--;
return 0;
}
int comparator(array2, n)
{
int i, AdjacentTriplets, one = 1, two = 2, three = 3;
int *arrayC = array2;
for (i = 0; i = n; i++)
if (arrayC[one] == arrayC[two] && arrayC[two] == arrayC[three])
AdjacentTriplets = 1;
else
AdjacentTriplets = AdjacentTriplets;
return 0;
}
int output(n, arrayC)
{
int A, *arrayO = arrayC;
for (A = 1; A =n; A++)
printf("%d The list is: ", arrayO[A]);
getchar();
getchar();
return 0;
}

Aucun commentaire:

Enregistrer un commentaire