SHOW:
|
|
- or go back to the newest paste.
1 | - | #include <stdio.h> |
1 | + | /* In order to compile this on my linux system |
2 | - | #include <math.h> |
2 | + | * even though the instructions were given like this |
3 | - | #include <string.h> |
3 | + | * $ gcc sine_print.c -o sine_print |
4 | - | |
4 | + | * I had to add -lm or it will return exception |
5 | - | int main() |
5 | + | * sine_print.c:(.text+0x8c): undefined reference to `sin' |
6 | - | { |
6 | + | * collect2: ld returned 1 exit status |
7 | - | int i; |
7 | + | * for some reason it wouldn't link the math.h at the compile step |
8 | - | int offset; |
8 | + | * So I typed $ gcc sine_print.c -lm -o sine_print |
9 | - | char sinstr[80]; |
9 | + | * latter I saw a post with a similar problem and they typed |
10 | - | |
10 | + | * $ gcc -Wall foo.c -o foo -lm |
11 | - | memset(sinstr,0x20, 80); |
11 | + | * I'm not sure if the syntax is a convention but the first way |
12 | - | sinstr[79] = '\0'; |
12 | + | * worked for me. -Wall I have seen when compiling stuff in Linux but need to |
13 | - | |
13 | + | * look at the manpage still so check out those flags before you type it |
14 | - | for (i = 0; i < 20; i++) { |
14 | + | |
15 | - | offset = 39 + (int)(39 * sin(M_PI * (float) i/10)): |
15 | + | * Also another weird thing is when I typed |
16 | - | |
16 | + | * gcc sine_print.c -o sine_print.c |
17 | - | sinstr[offset] = '*'; |
17 | + | * the file disappeared completely from my computer |
18 | - | printf("%s\n", sinstr); |
18 | + | * is this a bug or normal behavior? IDK |
19 | - | sinstr[offset] = ' '; |
19 | + | |
20 | - | } |
20 | + | * prints a sideways sine wave in ASCII chars |
21 | */ | |
22 | ||
23 | #include <stdio.h> | |
24 | #include <math.h> | |
25 | #include <string.h> | |
26 | ||
27 | int main() | |
28 | { | |
29 | int i; | |
30 | int offset; | |
31 | char sinstr[80]; | |
32 | ||
33 | memset(sinstr,0x20, 80); | |
34 | sinstr[79] = '\0'; | |
35 | ||
36 | for (i = 0; i < 20; i++) { | |
37 | offset = 39 + (int)(39 * sin(M_PI * (float) i/10)): | |
38 | ||
39 | sinstr[offset] = '*'; | |
40 | printf("%s\n", sinstr); | |
41 | sinstr[offset] = ' '; | |
42 | } | |
43 | } |