Home > Programming > Functions using the "C" programming language > example18.c |
/*
In this example we demonstrate how to use strings as function
parameters.
*/
#include <stdio.h>
#include <conio.h>
/* Function prototype, takes as parameter a pointer to character */
void print_str2( char * );
void main()
{
char s1[24] = "This is a fixed
string.";
char *s2 = "This is not a fixed
string.";
/* We call function print_str with parameter an array of
characters.*/
print_str2( s1 );
/* We call function print_str with parameter a pointer.*/
print_str2( s2 );
/* We call function print_str with parameter a constant string.*/
print_str2( "This is a constant string." );
getch();
}
void print_str2( char *s )
{
printf( "%s\n", s );
}
© 2004 Jim Valavanis