I would like to know the best way to make the following in c++, please. I have a Parser and a Gather classes; the gather consume the parser.
I have a method in the Parser class to parse my file with three parameters: process ID (int), path (string, char, char*...???) and string format (also I dont know which is best here - string, const string, etc...).
Its better to create a data[] in the Parse.method and return it, or to pass a reference to method, and keep the data variable in the gather class?
char* ProcInfoParser::parseStatm(const int _processPid, std::string _path, std::string _strFormat) { char path[32]; char* data[2042]; int tps = sysconf(_SC_CLK_TCK); int fd = open(path, O_RDONLY); if (fd < 0) { perror("open"); return "-1"; //wrong... } if (read(fd, data, 2048) == -1) { perror("read"); return "-1"; //wrong... } close(fd); char name[1024]; long unsigned int utime, virt; long int rss; sscanf(data, "%*d %s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu" " %*u %*d %*d %*d %*d %*d %*d %*u %lu %ld", name, &utime, &virt, &rss); //Iwish to use the _stringFormat variable here... return data; } I really dont know which one to choose between char (char*...) or string; I also want to make a path with the process ID like string.Format("/proc/(0)/statm",processID); does the sprintf function work like that? Maybe I should take a look at boost...
Thanks in advance