This is my code (is a working in progress to calculate in GB the size of disk in a system)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main ()
{
char line[128];
FILE* file = popen("/usr/sbin/prtvtoc /dev/rdsk/c0b0t2d0s0 |/usr/local/bin/grep 'slice 0' -A 2|grep length|cut -d : -f 3|cut -d '(' -f 1|cut -c 2-1000", "w");
printf("The size in 512b blocks of the disk /dev/rdsk/c0b0t2d0s0del is %s \n",file);
pclose(file);
return 0;
}
The output is very bad
The size in 512b blocks of the disk /dev/rdsk/c0b0t2d0s0del is
41929587
I want
The size in 512b blocks of the disk /dev/rdsk/c0b0t2d0s0del is 41929587
My idea is to store in a variable the output of popen pipe, but I don't know how to do: is possible?
EDIT1:
I have tried this line
printf("The size in 512b blocks of the disk /dev/rdsk/c0b0t2d0s0del is %d \n",*file);
but return 0