0

I have been working on PSET6 for ages and feel I have finally managed to clear most of the hiccups. However, despite my best efforts, whenever I click on a link, correct page isn't output; some weird alphanumeric string like this:

˜ÚýÛ)6çg€­ûype=˜Úý˜Úý˜Úý˜Úý©˜Úýÿÿÿÿÿÿÿÿ˜Úýÿÿÿÿÿÿÿÿ%22%2%24name2%3A%2 ójçgasad%22%ÿÿÿÿÿÿÿÿ€˜Úý€@@ÜÚýçf4çgerredBy%0@˜Úý€—Úýh%ó€ÿÿÀkçg÷i>çgt/html \0˜ÚýЗÚýÿ—Úý„@@˜ÚýÀà¸kçgœÿÿÿÈgÈö@@€˜Úý9@ÐY¡tA@ö@@€–Úý˜Úý¤6çÈ

appears. I feel it is an issue with my load function, but I'm not sure. Could someone please go through it for me?

http://pastebin.com/SSdBGA3T

1 Answer 1

0

Your load functions needs some work. When loading files you need to reallocate more space so you can read more information. I would suggest reading the file in char-by-char using realloc() and fgetc() with each iteration of some kind of loop (in that order).

EDIT:

For the while condition, you should only be checking if the value 'c' does not equal EOF. You also need to add one more char than what 'count' is to properly use realloc(). And while it isn't technically wrong, you don't need to use a separate variable when you realloc; you can simply use the one that you are allocating memory for, but this just depends on your own preference.

    while(c != EOF)
    {
        c = fgetc(file);
        buffer[count] = c;
        count++;
        buffer = realloc(buffer, count + 1);
    }

If this answers your question please accept it to keep up on forum maintenance.

3
  • Thanks, I worked on it but there is still some error I can't understand, even with GDB. New code pastebin.com/ZkahUacq Commented Aug 2, 2016 at 3:59
  • Looking better! Check my answer edit. Commented Aug 2, 2016 at 4:24
  • Thank you so much Commented Aug 3, 2016 at 3:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .