C++ Programmer here , need a quick solution for problem below.
I need to carry out following subtraction where input is taken from a file and desired numbers are stored in variables. However printf() is showing 0 as the value.
#include<stdio.h>
main()
{ system("clear");
system("cat /proc/meminfo | grep MemTotal");
system("cat /proc/meminfo | grep MemFree ");
int a=system("cat /proc/meminfo | grep MemTotal | grep -Eo [0-9]+");
int b=system("cat /proc/meminfo | grep MemFree | grep -Eo [0-9]+");
int c=a-b;
printf("%d \n",c);
}
Output is as following:
MemTotal: 3913212 kB
MemFree: 1769672 kB
3913212
1769388
0
Moreover is there a way to supress output from 7th and 8th line in code as i just need them to store in variables.
Edit : Fixed long int.
Thanks