title: C - my program prints weird stuff after reading from a file
body: <p>I am trying to make a program for an assignment to read ID3 tags. I don't have much code so far because I'm trying to learn how to work with the ID3 tags themselves. I made a little program which would read the first three letters and just print them back, just to see how the process of opening the file and closing it would work, etc.</p>
  
  <p>This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(int argc, char *argv[]) {
  
    char buf[4];
  
    if (argc == 2) {
      FILE *mp3 = fopen(argv[1], "r");
  
      fread(buf, 3, 1, mp3);
      buf[3] = "\0";
      printf("%s\n", buf);
      fclose(mp3);
      char a = buf[0];
      char b = buf[1];
      char c = buf[2];
      printf("%x\t%x\t%x\n", a, b, c);
    }
    return 0;
  }
  </code></pre>
  
  <p>It manages to print what is it supposed to (ID3) but then it makes some weird letters appear after the ID3 part. I added a part to print the hex values of those as well. </p>
  
  <p>I am new to C and I find this very difficult to understand. Also, I don't quite understand the differences between all the different ways of making and managing a string. So I would greatly appreciate any help regarding this and how to make it better and explain to me why etc.</p>