summaryrefslogtreecommitdiffstats
path: root/runtime/tests/string/string1.c
blob: 48773e5f5ffb01070edf17911a4fc07c14f61707 (plain)
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
37
38
39
40
41
42
43
44
/* test of Strings */

/* use very small buffer size for testing */
#define STP_PRINT_BUF_LEN 20
#define STP_NUM_STRINGS 4
#include "runtime.h"

int main ()
{
  String str[4];
  int i;

  for (i = 0; i < 4; i++)
    str[i] = _stp_string_init (i);

  _stp_sprintf(str[0], "Hello world");
  _stp_sprintf(str[1], "Red Hat");
  _stp_sprintf(str[2], "Intel");
  _stp_sprintf(str[3], "IBM");

  for (i = 0; i < 4; i++)
    _stp_print(str[i]);
  _stp_print_cstr("\n");

  for (i = 0; i < 4; i++) {
    _stp_print(str[i]);
    _stp_print(" / ");
  }
  _stp_print_cstr("\n");

  _stp_string_cat_cstr (str[1], " Inc.");
  _stp_print(str[1]);
  _stp_print("\n");

  _stp_string_cat_cstr (str[0], " ");
  _stp_string_cat_string (str[0], str[1]);
  _stp_print(str[0]);
  _stp_print("\n");

  _stp_sprintf(str[2], "%s\n", _stp_string_ptr(str[3]));
  _stp_print(str[2]);
  _stp_print_flush();
  return 0;
}