i have to create a graph by taking names of movies and the actors in that movies from a file. i have to create the graph and after i have to show the connection beteween the actors. does anyone know how i should do that in c? i prefer if you have coding. it would be very useful. thanks

Recommended Answers

All 3 Replies

Perhaps you should read the following rule from our forum rules and revise your post accordingly:
Do provide evidence of having done some work yourself if posting questions from assignments.

i opened the file and i read line by line with buffer 500 and i used strtok function to take in parts the name of the movie and the actors. in this while(!feof) i had this function and i think that i should push in a graph by list the name of the movie at the array and at the list the actors that play in the movie. i have a problem with my pointers in this part. so i cant continue because i have a segmentation fault

struct movies{
   struct node *movie[500];
   int size;
}
 
struct node{
   struct node *actor[50];
   struct node *next;
}
 
int main(){
    char f[20];
    FILE *inp;
    char buffer[500];
    printf("Give the name of the file");
    scanf("%s", &f);
    inp=fopen(arxeio, "r");
    char delims1[]=')';
    char delims2[]=',';
    char *result=NULL;
    i=0;
    while(!feof(inp)){
        fgets(buffer, 500, inp);
        result=strtok(buffer, delims1);
        movie[i]=result;
        while(result!=NULL){
        result=strtok(NULL, delims2);
        actor=(char *) malloc (sizeof(char));
        actor=result;
        actor->next=movie[i]->next;
       }
   i++;
}}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.