progs/C0.c
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 04 Oct 2014 15:31:58 +0100
changeset 202 6740798264c1
parent 198 Attic/programs/C0.c@2ce98ee39990
child 211 e6e160c7ea33
permissions -rw-r--r--
aded C0 files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#include <string.h>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
#include <stdio.h>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
#include <stdlib.h>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
void foo (char *bar)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  float my_float = 10.5;    // in hex: \x41\x28\x00\x00
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  char  buffer[28];        
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  printf("my float value = %f\n", my_float);
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  strcpy(buffer, bar);  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  printf("my float value = %f\n", my_float);
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
int main (int argc, char **argv)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
{
111
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
    19
  foo("my string is too long !!!!! ");                  // all is normal
112
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
    20
  //foo("my string is too long !!!!! \x10\x10\xc0\x42");  // overwrites my_float
24
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  return 0;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23