C Programming - Passing a pointer to array

Posted by Pedro on Stack Overflow See other posts from Stack Overflow or by Pedro
Published on 2010-05-05T18:00:24Z Indexed on 2010/05/05 18:08 UTC
Read the original article Hit count: 281

Filed under:
|
|

How do I pass a pointer value to an array of the struct;

For example, on a txt I have this:

John Doe;[email protected];214425532;

My code:

typedef struct Person{
    char name[100];
    char email[100];
    int phone;
}PERSON;

int main(){
   PERSON persons[100];
    FILE *fp;
    char *ap_name;
    char *ap_email;
    char *ap_phone;
    char line[100];
    fp=("text.txt","r");
    if(fp==NULL){
        exit(1);
    }
    else{
        fgets(line,100,fp);
        ap_name=strtok(line,";");
        ap_email=strtok(NULL,";");
        ap_phone=strtok(NULL,";");
    } 
    return 0;
}

My question is how can I pass the value of ap_name, ap_email, ap_phone to the struct? And, do I need to use all of these pointers?

© Stack Overflow or respective owner

Related posts about c

    Related posts about homework