Home > Programming > Functions using the "C" programming language > example21.c |
/*
In this example we demonstrate a function that returns a string
*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
/*
Function prototype
*/
char *str_max( char *, char * );
void main()
{
char *small = "A small string
!\0";
char *big = "A big string
!!!!!!!!!!!!!!!!!!!!!\0";
printf("%s",str_max( small, big ));
getch();
}
/*
Function str_max returns the string with the bigger length
*/
char *str_max( char *s1, char *s2 )
{
if ( strlen( s1 ) > strlen( s2 ) ) return
s1;
return s2;
}
© 2004 Jim Valavanis