First, I'm totally beginner in linux and C language, I can't relate C to c++ or java much when it comes to strings!. I'm using Fedora16 - linux - and I want to read a proc/[pid]/status file to get specific information from it, such as PPID and state, then I should print these info on the screen - command line terminal-. This must be done by writing a c script in gedit. My only issue is that I'm new to c, and dealing with strings in c seems very frustrating to me! I have already opened the file and view it on my terminal by executing the c file. Is there any possible way to store the whole content in one string variable and then I can tokenize it and store the chunks of data as in string array not char array, then I know where my wanted data is in the array and I can access it?
Here is my code though
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
void main()
{
const char line[200];
const char junk[200];
FILE *file = fopen("/proc/14/status", "r");
// while not end of the file
while(!feof(file)) {
fscanf(file,"%s",line); //Get text into line array
printf("%s\n", line);
//fscanf(file,"%[ \n\t\r]s",junk); //Remove any 'white space' characters
}//end while
fclose(file);
}
Output On Terminal: