0

I have to parse a text file with 3 different data types. I want it to be saved in a structure array with three members. My text file look like this:

>A B 45.78965
>A C 35.46731
>B C 46.78695

I have written a code and when I run it at the terminal, it only showed a blinking underscore then after a while the program stopped. What should I do?

 #include"stdio.h"
                #include"string.h"
                struct gra{
                    char from;
                    char to;
                    double w;
                };
            int main(){
                FILE* fp;
            fp=fopen("graph.txt","r");  
            int i=0;
                while(!feof(fp)) {
                fscanf(fp,"%[^\t]",&graph[i].from,&graph[i].to,&graph[i].w);
                i++;
             } fclose(fp);}
Aq Toh
  • 13
  • 2
  • That doesn't look like the correct code. Have you missed a declaration for `graph`? – simonc Oct 03 '13 at 06:46
  • 1
    A few points: First please format your code properly. Then please show a *complete* program, the one you have in your question is incomplete (e.g. what is `graph`?). And lastly, don't do `while (!feof(...))`, it will not work as you expect, because the end-of-file flag is not set until *after* you try to read beyond the end of the file. – Some programmer dude Oct 03 '13 at 06:47
  • @Aq Toh : Why are you asking same question twice? – Arya Oct 03 '13 at 06:52

0 Answers0