|
Array as
Arguments To Functions
Array cannot be
passed as an argument to a function. The address of the array
has to be passed. The address of an array is referred to by
using the name of the array without the subscripts.
#include
<stdio.h>
#include <string.h>
main ( )
{
int i, n = 0;
char x[10][12];
void reorder ( int n, char x [ ] [ 12 ] ) ;
clrscr ( );
printf("Enter each string on a separate : line
\n\n"); printf ("Type \'END\' when over
\n\n") ;
do
{
printf("String %d . ", n+1);
scanf("%s", x[n]);
} While (StrCItlp (X [n++] , "END"));
reorder (--n, x) ;
printf("Recorded list of strings :\n");
for (i = 0; i < n; ++i)
{
printf("\nString %d is %s", i+1, x[i]);
void reorder ( int n, char x [ ) [ 12 ] )
{
char temp[12];
int i, item;
for (item = 0; item < n - 1; ++item) {
for (i = item+1; i < n; ++i)
{
if(strcmp(x[item], x[i]) > 0)
{
strcpy (temp, x [item] ) ;
strcpy(x[item), x[i));
strcpy(x[i], temp);
}
}
}
return;
}
|