If you can modify the input file, use a delimiter other than a space and break each line in half with strtok:
Jamie lynn:20
Eric D. Mcdaniel:40
Joe:23
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
short int i=0;
size_t len;
char *line=NULL, *tok, DL[]=":\n";
FILE *fstRO=fopen("/root/test/test.txt", "r");
struct {char *name;
int age;
} *examp;
examp = malloc(sizeof(*examp));
while((getline(&line,&len,fstRO)) != -1) {
tok=strtok(line,DL);
if (i>0) examp = realloc(examp, (i+1) * sizeof(*examp));
examp[i].name=malloc(strlen(tok)+1);
strcpy(examp[i].name,tok);
tok=strtok(NULL,DL);
examp[i].age=atoi(tok);
i++;
}
free(line);
fclose(fstRO);
for (i=0;i<3;i++) printf("%s is %d\n", examp[i].name,examp[i].age);
}
If you can't change anything about the input file, you'll have to do the character by charater method (and hope that no one has a wierd name like "Bob 35"). Beware: I don't know what the non-GNU equivalent of getline is.