Advertisement
rfmonk

sine_print_with_comments.c

Mar 8th, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* In order to compile this on my linux system
  2.  * even though the instructions were given like this
  3.  * $ gcc sine_print.c -o sine_print
  4.  * I had to add -lm or it will return exception
  5.  * sine_print.c:(.text+0x8c): undefined reference to `sin'
  6.  * collect2: ld returned 1 exit status
  7.  * for some reason it wouldn't link the math.h at the compile step
  8.  * So I typed $ gcc sine_print.c -lm -o sine_print
  9.  * latter I saw a post with a similar problem and they typed
  10.  * $ gcc -Wall foo.c -o foo -lm
  11.  * I'm not sure if the syntax is a convention but the first way
  12.  * worked for me. -Wall I have seen when compiling stuff in Linux but need to
  13.  * look at the manpage still so check out those flags before you type it
  14.  
  15.  * Also another weird thing is when I typed
  16.  * gcc sine_print.c -o sine_print.c
  17.  * the file disappeared completely from my computer
  18.  * is this a bug or normal behavior? IDK
  19.  
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement