Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include "stdlib.h"
  2. #include "stdio.h"
  3. #include "string.h"
  4. #include "sys/types.h"
  5. #include "sys/sysinfo.h"
  6.  
  7. int main()
  8. {
  9.     char quit = '1';
  10.     FILE* file;
  11.     unsigned long physMemUsed = 0;
  12.     char lose[200];
  13.     char mem_str[200];
  14.  
  15.  
  16.  
  17.     while (quit != '0') {
  18.  
  19.         file = fopen("/proc/meminfo", "r");
  20.         fgets(lose, 200, file);
  21.         fgets(lose, 200, file);
  22.         fscanf(file, "%s", mem_str);
  23.         fclose(file);
  24.  
  25.         int i = 15;
  26.         while (mem_str[i] != 'k') {
  27.  
  28.             if (mem_str[i] <= '9'|| mem_str[i] >= '0' ){
  29.                 physMemUsed = physMemUsed * 10 + atoi(&mem_str[i]);
  30.             }
  31.             ++i;
  32.         }
  33.  
  34.  
  35.         physMemUsed = physMemUsed / 1024;
  36.  
  37.         printf("%lu", physMemUsed);
  38.         printf("\n");
  39.         quit = getchar();
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement