0

I'm trying to create a project about graphs and using BFS in c. But I have some problems from reading and also writing after when I fill the nodes from the command screen. If you can help about it I would be appreciated.

void createGraph(){
    int i,j;
    for(i=0;i<100;i++){
        for(j=0;j<100;j++){
            a[i][j]=0;
        }
    }
    i=0;j=0;
    while(1){
        printf("Enter the from n to vertices (Enter -1 to stop): ");
        scanf("%d",&i);
        scanf("%d", &j);
        if(i == -1){
            return;
        }
        else{
            a[i][j]=1;
        }
    }
}

Now I can just enter the nodes from the command screen and do the works, so how can I open the file, print the edges and nodes to this file, and after that reading from it when I need.

Kaan
  • 11
  • 1

1 Answers1

0

Tutorialspoint has a good explanation.

Just remember that calling Sleep() (or something similar) before closing the file will not save changes made to it. Also remember that if you open a file for writing, you can't read from it properly. You must first close the file, then open for reading.

Correct me if I'm wrong.