# Skenz - How To Wiki

### Site Tools

cs:c_language:functions_and_arrays_1

# Functions and Arrays (Example 1)

Concepts:
Passage of arrays to functions (arrays in the C programming language are passed to functions by reference)

Text:
Implement a function that:

• receives in input a vector of characters and its dimension
• transforms all the upper case characters present in the vector in lower case characters and vice versa
• do nothing for non alphabetic characters
• the function must return the number of transformations

The calling function (`main`) must print the transformed vector as well as the number of transformations performed.

Solution:

functions_arrays_1.c
```/* Implement a function that receives in input a vector of characters and its dimension.
The function must transform all the upper case characters present in the vector in lower case characters and vice versa.
It does not have to do anything for non alphabetic characters present in the array.
The function must return the number of transformations.
The calling function (''main'') must print the transformed vector as well as the number of transformations performed. */

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

#define SIZE 8

int trasform(char v[], int dim){
int i;
int n_transf=0;

for(i=0; i<dim; i++)
if (isalpha(v[i])){
if (islower(v[i]))
v[i] = toupper(v[i]);
else
v[i] = tolower(v[i]);
n_transf++;
}

return n_transf;
}

int main(){
char vet[SIZE]={'a', 'B', 'C', '1', '?', 'x', 'Y', '*'};
int i;
int n_trasformations;

n_trasformations = trasform(vet, SIZE);

for(i=0; i<SIZE-1; i++)
printf("%c ", vet[i]);
printf("%c\n", vet[SIZE-1]);

printf("Number of transformations: %d\n", n_trasformations);

return 0;
}``` 