Sucheta Ghosh napisał(a):
> I wished to read a file and get some lines from there like this:
>       -----
>       fp=fopen("filename", "r");
>       for(k=0; k<8; k++){
>               n=a[k];
>               for (i=1; i<=n; i++) //Here 'n' is the line number
>                       fgets(s, 100, fp);
>               puts(s);
>               rewind(fp);
>       }
>       -----
>       -----
> This is the code snippet, which is working so well after compiling with 
> 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a 
> runtime error is occuring before execution of 'fgets'. I have already 
> included 'stdio.h', but even then it is not executing.
> 
> Do you have any idea that how to overcome this problem?

I can see some problems here, but that's not really GTK-related;
well - there's also a change that included snippet was simply
too short

1) no error checking for fopen(), fgets() - You don't to anything
    if they fail (and that's most probable)

2) can't see any fclose() - multiple "fopen()"s without closing
    the file is BAD :)

3) You're reading the same file 8 times - and that's *at least*
non-optimal - of course that depends on what exactly you're going
to achieve, however I'm quite convinced

4) I'd be really careful about placing some external file operations
nside of a callback function..... but this depends on your overall
application purpose and design.

Best regards
Waldek

----------------------------------------------------------------------
Czas pozegnac finansowe problemy.
Kredyt Citibank - prosty kredyt na wszystkie potrzeby.
Sprawdz: http://link.interia.pl/f19a5

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to