05-memory_leak.c 640 Bytes
Newer Older
Xavier Besseron's avatar
PS 2021  
Xavier Besseron committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// This program will print all its parameters in uppercase


// Convert buffer to uppercase
char* uppercase( char* buffer )
{
  int size = strlen(buffer);
  char* buffer_up = malloc( size+1 );
  int i;
  for ( i = 0 ; i < size ; i++ )
  {
    if ( buffer[i] >= 'a' && buffer[i] <= 'z' )
      buffer_up[i] = buffer[i] + 'A' - 'a';
    else
      buffer_up[i] = buffer[i];
  }
  buffer_up[size] = '\0';

  return buffer_up;
}

int main(int argc, char** argv)
{
  int i;
  for( i = 0 ; i < argc ; i++ )
  {
    printf("%s ", uppercase(argv[i]) );
  }
  printf("\n");

  return 0;
}