title: Getting RAM size in C, linux, non-precise result
body: <p>I have 16 GB RAM on my computer at school running Ubuntu 13.10. I wrote a simple C program to get the total RAM but it shows non-precise results, instead of 16 it prints out 15. How to make it to be precise, even for smaller RAM sizes? At home I have a computer with 768 MB RAM and my program shows there wrong results too :( </p>
  
  <pre><code>#include &lt;sys/sysctl.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  void getMemoryInfo()
  {
      FILE *meminfo = fopen("/proc/meminfo", "r");
      int totalMemory = 0;
      if(meminfo == NULL)
      {
          exit(-1);
      }
      char buff[256];
      while(fgets(buff, sizeof(buff), meminfo))
      {
          int ramKB;
          if(sscanf(buff, "MemTotal: %d kB", &amp;ramKB) == 1)
          {
              totalMemory = ramKB/1024.0;
              totalMemory = totalMemory/1024.0;
          }
      }
      if(fclose(meminfo) != 0)
      {
          exit(-1);
      }
      printf("%d\n", totalMemory);
  }
  
  int main()
  {
      getMemoryInfo();
  
      return 0;
  }
  </code></pre>