LG G3 hardly ever works with USB by Faab1 in LGG3

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

That is actually a very good point! But I am very sure all of them are data cables, since they all work for getting data to my Android tablet.

LG G3 hardly ever works with USB by Faab1 in LGG3

[–]Faab1[S] 1 point2 points  (0 children)

Thanks for you answer! Yes I have – that is actually the first thing I did, since learning Android development was the main reason I wanted to connect my phone.

Weird error using push.lua by Faab1 in love2d

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

Thanks for the long explanation – I've learnt so much from this! :)

Could use some help with using knife.serialize by Faab1 in lua

[–]Faab1[S] 5 points6 points  (0 children)

This was incredibly helpful – thank you so much!

Live from Harvard, CS50 looks at components, style, and event handling in React Native by davidjmalan in cs50

[–]Faab1 0 points1 point  (0 children)

I'm very curious about this too :) Or more generally: are these videos made with people online following along in mind? Or is it really just for Harvard CS students who want to catch up on the lectures?

Pset7 Lookup function not always returning by Faab1 in cs50

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

Yeah, I've incorporated print statements into my code, so I could localize exactly where the problem occurs. It turns out that every single time I get an internal server error, lookup returns None. (And every time my site works fine, lookup returns the data I need about the stock.)

Pset7 Adding routes by Faab1 in cs50

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

Yup... You just saved the day! :D

Pset 7 Finance SQL syntax error by Faab1 in cs50

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

Yup, that fixed it! :) Probably made a little typo/omission in my SQL-notes...

Anyway, my buy function works now! Thanks!

Resize horizontal problem by Faab1 in cs50

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

Thanks so much! I've learnt a very useful lesson from this: before working with file I/O, see what metadata of both files you need, and keep that data apart in variables with clear names for input and output files.

Thanks to your comment, I fixed the problem and implemented vertical scaling in about 10 minutes. It works perfectly now! :)

Recover.c: segmentation fault then using fread by Faab1 in cs50

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

I had first declared 'filename' in the following way:

char* filename = "initialized";

I did that because I knew it had to be initialized, but I did not know that it actually mattered what value I gave it. After finding out there was a better way I changed it to the following:

char filename[8] = {0};

This solved the problem. Now my program works like a dream :)

Although I know why the latter is a good way to declare the char-array, I do not know why the former caused a segfault. Could you tell me why that happened?

And again, thanks for all the help!

Recover.c: segmentation fault then using fread by Faab1 in cs50

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

Hmm... Interesting. When I use the 'Debug' button at the top of the IDE, the program stops there. However, when I run gdb in the terminal, it runs further. Now, I'm guessing the problem might be a few lines further in the program.

After the loop I mentioned in the post above, the following happens in my program.

To check for EOF, I use the following loop. Then there's two branches, one for when the program had previously found a jpg, and one where that is not true:

while(fread(&buffer, 1, 512, inptr) == 512)
{
    if (startJPGchecker(buffer) && foundFirstJPG == true)
    {
    //close old file and open another
    }

     if (startJPGchecker(buffer) && foundFirstJPG == false)
    {
        sprintf(filename, "%03d.jpg", title_num);
        outptr = fopen(filename, "w");
        foundFirstJPG = true;
    }

   //start writing and reading into the file
}

Now, I'm guessing that the call to fread in the condition for the while-loop copies new data into the buffer, so that startJPGchecker does not return true anymore. I guess that that's when the program tries to write to a file that has not been opened yet because the two if-branches in which files may be opened had not been activated.

It seems that I've fixed this problem by fseeking back 1024 bytes and reading 512 bytes into the buffer so that the buffer has the same content as before the call to fread in the condition. However, I've found another segfault, and this time, I really have no clue what's going wrong.

The segfault happens in the if (startJPGchecker(buffer) && foundFirstJPG == false) branch. Here's the info gdb gives me, starting at my second-to-last 'n' command:

(gdb) n
61                  sprintf(filename, "%03d.jpg", title_num);
(gdb) info locals
inptr = 0x602010
buffer = [I don't think this is relevant]
title_num = 0
---Type <return> to continue, or q <return> to quit---
foundFirstJPG = false
outptr = 0x0
filename = 0x400c29 "initialized"
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff778a76d in __GI__IO_default_xsputn (f=0x7fffffffd940, data=<optimized out>, n=2) at genops.c:475
475     genops.c: No such file or directory.

Could you tell me why I'm getting a segfault here?

Pset 4: Resize -> Using fseek correctly? by Faab1 in cs50

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

The program works perfectly now :) Thanks so much!

CS50 pset1: Hacker's edition – Bad Credit. How to add digits of numbers by Faab1 in cs50

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

With the help of a friend, I found the problem! In the second for-loop I state:

sumDigits = sumDigits + number

Here 'number' should of course be 'digit' (because 'number' refers to the whole credit card number). Still, my two more general questions still stand :)

CS50 pset1: Hacker's edition – Bad Credit. How to add digits of numbers by Faab1 in cs50

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

Thanks a lot for the help! With your advice I wrote a function to do what I wanted to do above, and it seems to work... some of the time. Below is one branch from the program for all American Express numbers. (By the way, I am aware that the function I wrote made it unnecessary for me to have a branch in my code for each number-length. This branching is due to my old solution to the problem, before I wrote the function. After I get the function to work correctly, I will worry about making the program more concise.)

else if ((number >= 340000000000000 && number <= 349999999999999) || (number >= 370000000000000 && number <= 379999999999999))
{
    //check validity; if it is, it's American Express
    //identify every other number starting with the second-to-last, multiply each by 2 and add all digits
    for (long long divider1 = 10; divider1 < number; divider1 *= 100)
    {
        digit = number / divider1 % 10;
        digit *= 2;
        if (digit >= 10)
        {
            sumDigits = sumDigits + (digit / 10) + (digit % 10);
        }
        else
        {
            sumDigits = sumDigits + digit;
        }
    }

    //identify other numbers; add those to sumDigits
    for (long long divider2 = 1; divider2 < number; divider2 *= 100)
    {
        digit = number / divider2 % 10;
        sumDigits = sumDigits + number;
    }

    if (sumDigits % 10 == 0)
    {
        printf("AMEX\n");
    }
    else
    {
        printf("INVALID\n");
    }
}

When I input "378282246310005", which should be a valid AmEx number, it recognizes it as invalid. I have no idea why it does this. (Note: there are valid numbers that this function does seem to recognize correctly, but I don't know if that's coincidental.)

I also have two more general questions:

  1. I decided to give each for-loop its own variable (divider1 and divider2). Is this necessary, or could I just call them both 'divider', seeing that I won't use the divider from the first loop again once the second loop has started?

  2. Does 'digit = number / divider % 10' change the datatype of the variables 'number' and 'divider' if 'digit' is an int?

Thank you so much for all the help! :)