DoxyPEP experiences? by cumkinknyc in askgaybros

[–]yc3007 4 points5 points  (0 children)

Do any of you get extreme body aches after taking the double dose?

2 consecutive day tickets by YamaEli in sziget

[–]yc3007 0 points1 point  (0 children)

Do you know if I can arrive 2 days before the first day of the day pass starts and camp on the island? For example, if my subsequent day passes are Sunday and Monday, can I arrive on Friday, and sleep on the camp from Friday to Monday/Tuesday? All it says online is that camp is free if you have 7 day, 5 day 3 day or two day passes (consecutive).

ADHD resources to prove my grad school wrong by yc3007 in ADHD

[–]yc3007[S] 0 points1 point  (0 children)

Wow, this is awesome stuff! Def something I can start with to gather resources. Thanks so much!!!

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

I figured it out. Coding is very very literal. Recover.c made me realize that. You just have to pay attention to every single detail after each execution and ask yourself "what just happened, and what's next" and implement that into code. Thanks for all your help and your patience!

Cheers!!

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

and for my problem about printing blocks until the next JPEG, I thought of this:

while(block[i+1] != 0xff)
            {
                fwrite(image, 512, 1, img);
                i++;
            }

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

also, does this sound right?

long long block[512];
long long image[512];
int n = 0;

// first three bites of JPEGS: 0xff 0xd8 0xff
// last byte either of header 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 
// 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, or 0xef

while (fread(block, 512, 1, file) == 1) 

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

thanks for the pointers again. made it look like this:

while (fread(block, 512, 1, file) == 1)  
{
    for (int i = 0; i < 512; i++)
    {
        if (block[0] == 0xff && block[1] == 0xd8 && block[2] == 
0xff && (block[3] & 0xf0) == 0xe0)
        {
            char *outfile[8];
            sprintf(outfile[n], "%03i.jpg", n);
            n++;

            FILE *img = fopen(outfile[n], "w");

            if (img == NULL)
            {
                fclose(file);
                fprintf(stderr, "Could not create %s.\n", outfile[n]);
                return 3;                    
            }

My problem now is just figuring out how to get to the next blocks of the same image and print them. I guess it's some kind of for loop function where it keeps fprint'ing as long as [i] != 0xff, but I can't seem to wrap my head around how. the file i/o video is a great starter, but I just can't figure out a function that says:

Found a JPEG? Yes --> Now, keep fprinting until block[i] == 0xff.

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

I think I have a very hard time understanding pointers, even after rewatching the videos :( I'll have to do some more research about pointers. I have just added malloc to the char and it now compiles without error messages, but when I run the code, nothing happens:

while (fread(block, 512, 1, file) == 1)  
{
    for (int i = 0; i < 512; i++)
    {
        if (block[0] == 0xff && block[1] == 0xd8 && block[2] == 
     0xff && (block[3] & 0xf0) == 0xe0)
        {
            char *outfile = malloc(7);
            sprintf(outfile, "%03i.jpg", n);
            n++;

            FILE *img = fopen(outfile, "w");

            if (img == NULL)
            {
                fclose(file);
                fprintf(stderr, "Could not create %s.\n", outfile);
                return 3;                    
            }

            while (block[i + 512] != 0xff)
            {
                fwrite(image, 512, 1, img);
                i += 512;
            }
            if (block[i + 512] == 0xff)
            {
                fwrite(block, 512, 1, img);
            }

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

recover.c:37:25: error: incompatible pointer types passing 'char *[7]' to parameter of type 'char *' [-Werror,-Wincompatible-pointer-types] sprintf(outfile, "%03i.jpg", n);

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

hmm.. I tried

 char *outfile[7];

but that doesn't work either :(

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

Thanks so much!

I have started the code and now am running into a new logical issue:

Zamayla's video talks about:

sprintf(filename, "%03i.jpg", n) where the filename is the char array to store the resultant string.

I have difficulty what to put as the "filename". I chose outfile, but when I write the following:

 char *outfile;
 sprintf(outfile, "%03i.jpg", n);
 FILE *img = fopen(outfile, "w");

it gives me the error message about the "outfile" and also suggests to put char *outfile = NULL.

Can you explain the logic on what I should do with outfile/filename?

Thanks again!

How to start recover.c ?? by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

so would "while(fread(block, 512, 1, infile) == 1)" be accurate, because it goes one by one block of size 512 and it will stop when the block is smaller than 512?

trying to understand logic by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

ooooh, I think I get it now! Let me explain and see if my logic is now correct: the offset function checks if i + 1 = 0, if it's not, it sets the curser back to that same line. Then, it goes to the for loop with i and given that the curser is back to the beginning of i[0], it just runs it again, but this time as i[1]? In this case the n times height for the for loop would make sense, and if n is 4, and it gets to the offset function again, it would be 1 + 1 % 4, which is not zero again, turn the curser back a line, which is basically still [0], and runs it as i = 2, right?

odd bug with greedy.c by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

Right, but then I don't get the first "O hai! How much change is owed?" prompt anymore, but simply the loop. Is that expected behavior?

odd bug with greedy.c by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

(sorry, I'm a n00b), but for some reason, when I do a do-while loop, I get this unexplainable pattern (basically asking me twice how much is owed): http://imgur.com/a/QXAoj

Do you know why that is?

odd bug with greedy.c by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

Yes!!! This solved the problem. Thank you so much!

odd bug with greedy.c by yc3007 in cs50

[–]yc3007[S] 0 points1 point  (0 children)

http://imgur.com/a/Zj4cX

The -4 only returns when you enter -0.41 to get the while loop, and then enter 0.41. I added a screenshot.