Get information from a line

I am writing a small program, that get information from lines of a text file. A line content some fields:
name char[20]
heigh float
alt int
sex char (only a character 'w' or 'm')

A line look like: maron hugen 34.5 32 m.I don't know how to split up the date into different variable types. I have treid but it didn't work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
char temp[40]; char temp2[10]; int b=0;
        strcpy(temp,m.c_str());                 // convert from a string to array of char                 
        
        int a=0;
        while(a<40){
                    if(temp[a]==' '&&temp[a+1]>47&&temp[a+1]<58){      
                                  strcpy(name,temp[a-1]);                        
                                  break;
                                  }
                    a++;
                    }
        a++;
        
        while(a<40){
                    temp2[b]=temp[a];                           
                    if(temp[a+1]==' '){                            
                                  high=strtof(temp2[b]); break;  
                                  }
                    a++; b++;
                    }
        a +=2; b=0;
        while(a<40){
                    temp2[b]=temp[a];
                    if(temp[a+1]==' '){
                                      age=atoi(temp2[b]); break; 
                                      }
                    a++; b++;
                    }
        
        t.sex=temp[a+2];
Topic archived. No new replies allowed.