forked from grigory-rechistov/simlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug-example.tex
44 lines (37 loc) · 1018 Bytes
/
debug-example.tex
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
\chapter{Программа debug_example.c}\label{chap:debug-example}
\begin{lstlisting}
/*
* This program reads input and converts it to uppercase.
* It has an intentional bug included that makes it crash on certain inputs.
*
* Usage: stdin - input string.
* Compile with gcc -static -g debug_example.c -o debug_example
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void read_input(char* in) {
char symbol;
in[0] = 0; // initialize the string with zero length
while((symbol = getchar()) != EOF) {
*in++ = symbol;
}
*in = 0; // close the string
}
void convert_to_uppercase(char * in, char *out) {
int i;
for (i =0; i <= strlen(in); i++) {
if (isalpha(in[i]))
out[i] = toupper(in[i]);
else
out[i] = in[i];
}
}
int main(int argc, char** argv) {
char input[32], *output;
read_input(input);
convert_to_uppercase(input, output);
printf("%s\n", output);
return 0;
}
\end{lstlisting}