Issue of reading input from filepointer : I'm trying to do a DFS search on a given graph using the following code:

        #include <iostream>
        #include <cstring>
        #include <cstdlib>
        #include <cstdio>
        #include <vector>
        #include <queue>

        typedef struct G{
        int vertex1;
        int vertex2;
        float num;
        } graph;

        typedef struct adj{
        std::vector<int> element;
        }adj;
        
        void dfs (int v, bool marked[], adj*p){
        marked[v]=true;
        std::vector<int>::iterator i;
        for (i=p[v].element.begin(); i!=p[v].element.end();i++){
        if (!marked[*i]){
        dfs(*i, marked, p);
        }
        }
        }
        void Search(adj*p, int*tvertex){
        bool *marked=new bool[*tvertex];
        for (int v=0; v<*tvertex; v++){
        marked[v]=false;
        q.push(v);
        }
        for (int v=0; v<*tvertex;v++){
        if (marked[v]==false){
        dfs(v, marked,p);
        while (!q.empty()){
        bfs(v, marked,p, q);
        }
        }
        }
        }

        void buildadj(graph*g, adj*p, int * tvertex, int *edge ){
        for (int e=0; e<*edge; e++){ 
        p[g[e].vertex1].element.push_back(g[e].vertex2);
        p[g[e].vertex2].element.push_back(g[e].vertex1);
        }
        }

        void readInData(FILE *fp, graph*g, int *tvertex) {
        char buffer[500];
        char *token;
        const char delimiters[] = " ";
        int i;
        int n;
        memset(buffer, 0, 499);
        for(i = 0;!feof(fp);) {
        i++;
        if (i>=2){
        fscanf(fp, " %[^\n]", buffer);
        token = strtok(buffer, delimiters);
        n = (int) atoi(token); 
        g[i-2].vertex1 = n;
        g[i-2].vertex2 =  (int) atoi(strtok(NULL, delimiters));
        g[i-2].num = (float)atof(strtok(NULL, delimiters));
        }
        }
        }
        void readstrct(FILE *fp,int*edge, int*tvertex){
        int i;
        int a[2];
        while (EOF!=fscanf(fp, "%d\n", &a[i]))	{
        i++;     
        if(i>=2){
        break;
        }
        }
        *tvertex=a[0];
        *edge=a[1];
        }

        void sendMessage() {
        char message[200];
        sprintf(message, "Needs to be in this format:\n./exe_name 
        NAME.txt\n");
        printf("%s", message);
        }
       int main(int argc, char * argv[]) {
       FILE *fp;
       int edge;
       int tvertex;
       if(argc < 2) {
       printf("File not given\n");
       sendMessage();
       return 0;
       }

       fp=fopen(argv[1], "r");
       if(fp == NULL) {
       printf("file not found\n");
       sendMessage();
       return 0;
       }
       readstrct(fp,&edge, &tvertex);
       graph *g=new graph[edge];
       adj *p=new adj[tvertex];
       readInData(fp, g, &tvertex);
       buildadj(g,p,&tvertex, &edge);
       Search(p,&tvertex);
       

}


The input is of the following form:

    13
    13
    0 5 2.1
    4 3 2.3
    0 1 3.2
    9 12 4.2
    6 4 5.1
    5 4 2.2
    0 2 0.2
    11 12 0.22
    9 10 0.22
    0 6 0.22
    7 8 0.22
    9 11 0.22
    5 3 0.22
I intend to read the first two lines and returns the  edges and vertex num in the 'readstruct' function. Line 3 and Line 15 are read in the readIndata function. The code is compling fine using g++. But gives segmentation fault when reading input. I tried to use gdb to debug and found that the code continues to read the file when it reaches line 15(or i=13) in  readIndata function. 

Best