Calling Functions with Arrays - C Function

C examples for Function:Function Parameter

Introduction

When an array is used as a function argument, its address is passed to a function.

Demo Code

#include <stdio.h>
#include <ctype.h>

void print_upper(char *string);

int main(void)
{
   char s[80];//w  ww  .  java  2 s . c om

   printf("Enter a string: ");
   gets_s(s);
   print_upper(s);
   printf("\ns is now uppercase: %s", s);
   return 0;
}

/* Print a string in uppercase. */
void print_upper(char *string)
{
   register int t;

   for (t = 0; string[t]; ++t) {
      string[t] = toupper(string[t]);
      putchar(string[t]);
   }
}

Related Tutorials