There is no error in how you are using garray but rather generic c programming errors.Firstly the error message should clue you in. Its telling you arguement 3 of fscan has type char** when type char* is needed. I.e. it should be

I saw the fscanf and the for loop error. One other issue, though it's not contributing to the error messages, is that you opened the file with fopen() but didn't close it using fclose().

I'm not sure what the file extension of the file is your trying to read but it appears to be an .html file. Anyhow I did a test and replaced it with a .txt file.I didn't comment because with these changes the errors go away but program seg faults and I was trying to figure out why.

I don't see a Glib replacement listed for fscanf. The only ones dealing with files are g_fprintf and g_vfprintf. Still I'd like to know why it's not working with fscanf.If you do end up going with one of the Glib replacements be aware that:

Quote:

... you'll have to explicitly include <glib/gprintf.h> in order to use the GLib printf() functions.

no direct fscanf replacement I know of. I use g_file_get_contents and then g_strsplit.At the moment your %s will delimit off whitespace which will not make much sense when you are using latex tags. You'd be better off storing entire lines or for the case of latex/bibtex delimit off two consecutive EndOfLine markers (and then potentially further according to latex curly bracketing or key=value entries for bibtex). g_strsplit gives a good deal of flexibility in how you might want to split up the text.I don't get any segfaults with things changed over to this system. Here's a little example:

Of course there's no real need for the garray in this example, it's just for demonstration. Though you may perform further manipulations that may make it useful over the char** case.You might note the lack of buffers in this case through the advantage of using built in dynamic allocation of memory. Thus there are no overflows to worry about.Not sure why you are getting segfaults yet. Will look into it.

Just for the sake of completeness, your main problem with fscanf is that you need preallocated memory in which fscanf can write to. All you did in your code is allocate ten pointers to char and they all pointed nowhere.

You probably need to get a book on C, since most of your problems is not GLib/GTK+ related at all.

You probably need to get a book on C, since most of your problems is not GLib/GTK+ related at all.

Yes, I am also feeling that I need to learn C a fresh. My C knowledge is mostly based on web tutorials(like few tutorials given in tutorial section of this forum as well). Though I have a K&R, I am ashemed to accept the fact that I have not managed to learn much from that.May I request you people to suggest me some "good" book that incorporates a lot of example?

My favorite books on C are "Sams Teach Yourself C for Linux Programming in 21 Days" by Eric De Castro Lopo (great book for beginners - I started with that book) and "Expert C Programming: Deep C Secrets" by Peter van der Linden. After that, it's been all reading others' people code for me.

Who is online

Users browsing this forum: Google [Bot] and 6 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum