Hello,
I have this problem.
Use the function that you just wrote to read a sequence of numbers. Put them into an array declared in main, by repeatedly calling the function. Sort them into ascending numerical order, then print the sorted list.
So I thought this can work
/*
* =====================================================================================
*
* Filename: test.c
*
* Description: test
*
* Version: 1.0
* Created: 06-05-11 22:46:11
* Revision: none
* Compiler: gcc
*
* Author: Dr. Fritz Mehner (mn), mehner@fh-swf.de
* Company: FH Südwestfalen, Iserlohn
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
int uitkomst = 0 ;
int getallen[10];
int teller= 0;
int
verwerken (letter )
{
if (teller <= 9)
{
getallen[teller] = letter;
teller = teller +1 ;
uitkomst = 0 ;
}
else
{
uitkomst = -1 ;
}
return uitkomst ;
} /* ---- end of function verwerken ----- */
int
main ( int argc, char *argv[] )
{
int ch;
ch = getchar();
uitkomst=0;
if (uitkomst <> -1)
{
while(ch != 'a')
{
invoer= verwerken(ch);
ch = getchar();
}
}
printf ("De uitkomst is : %d", uitkomst);
return (EXIT_SUCCESS);
}
So if the user enters more then 10 numbers and if the user enters "a" the sorting must begin.
But I can't figure out how to stop the entering of numbers without using a and statement.
Can anyone help me ?
Roelof