I have the following line from a file:
Name: variable_length_string
and I’d like to extract the substring:
variable_length_string
from it. This is what I have:
char* getProcStatus(const char* path) {
printf("path: %s", path);
char* chrptr_ProcessStatus = NULL;
FILE* fd_status = fopen (path, "rt");
char line[300];
char name[5];
char* procName = NULL;
if ( fd_status ) {
if (fgets(line, sizeof(line), fd_status) != NULL) {
sscanf(line, "%s%s", name, procName);
if (procName != NULL) {
printf("%s", procName);
fclose(fd_status);
return procName;
}
}
}
return procName;
}
I tried creating a name buffer just to store away the “Name: ” somewhere but it isn’t working at all (if (procName != NULL)) isnt executing.
How do I get a substring of variable length? All I know is that it ends with ‘n’ and it’ll always begin with ‘Next: ‘