1 /*
2 * mpatrol
3 * A library for controlling and tracing dynamic memory allocations.
4 * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * MA 02111-1307, USA.
20 */
21
22
23 /*
24 * Reads the standard input file stream, converts all lowercase
25 * characters to uppercase, and displays all non-empty lines to the
26 * standard output file stream.
27 */
28
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <ctype.h>
34
35
strtoupper(char * s)36 char *strtoupper(char *s)
37 {
38 char *t;
39 size_t i, l;
40
41 l = strlen(s);
42 if ((t = (char *) malloc(l + 1)) == NULL)
43 {
44 fputs("strtoupper: out of memory\n", stderr);
45 exit(EXIT_FAILURE);
46 }
47 for (i = 0; i < l; i++)
48 t[i] = toupper(s[i]);
49 t[i] = '\0';
50 return t;
51 }
52
53
main(void)54 int main(void)
55 {
56 char *b, *s;
57
58 b = (char *) malloc(BUFSIZ);
59 while (gets(b))
60 {
61 s = strtoupper(b);
62 if (*s != '\0')
63 puts(s);
64 free(s);
65 }
66 free(b);
67 return EXIT_SUCCESS;
68 }
69