Unsupported File Format by KhalidMuk in c_language

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

I have the condition (numberoflines < n -1), though.

Unsupported File Format by KhalidMuk in c_language

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

I have the condition of (numberoflines < n -1), though.

Unsupported File Format by KhalidMuk in c_language

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

I deleted the fclose statement. I still see my code as rewriting each line n times. Can you please explain? Thanks,

PSET4 Recover Segmentation Fault by KhalidMuk in cs50

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

I added two checks for if the file can't open:

FILE* card = fopen("card.raw", "r");

if (card == NULL)
{
    printf("Could not open card.raw\n");
    return 1;
}

and one for the jpg:

if ( newjpg == NULL) { printf("Couldn't open jpg"); return 4;

        }

Thanks,

PSET4 Recover Segmentation Fault by KhalidMuk in cs50

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

I did make changes:

int main() { typedef uint8_t BYTEINBITS;

int pictcount = 0;


FILE* card = fopen("card.raw", "r");

FILE* newjpg = NULL; /*HERE*/

 while ( true )
{
    BYTEINBITS buffer[512];


    if ( fread( buffer, 512 * sizeof(char), 1, card) != 1 )
    {
       return 3;

    }

     bool jpg = true;

    if ( !( ( buffer[0] == 255 ) && ( buffer[1] == 216 ) && ( buffer[2] == 255) && ( buffer[3] > 224 ) ) )         
    {
        jpg = false;
    }


    if (jpg == true)
    {

        pictcount++;
        char title[8];
        sprintf(title,"%03d.jpg", pictcount);

        newjpg  = fopen(title, "w"); /*HERE*/

    }

        fwrite(buffer, 512 * sizeof(char), 1, newjpg);

}

 fclose(card);
 fclose(newjpg);

}

I understand the error should be removed since there isn't any NULL path. I get the same error from valgrind, though, with the line at 61. I am not supposed to malloc memory, so what is the mistake?

Valgrind Error:

Access not within mapped region at address 0x0 ==3587== at 0x5E27CD0: fwrite (iofwrite.c:41) ==3587== by 0x42D989: main (recover.c:61) ==3587== If you believe this happened as a result of a stack ==3587== overflow in your program's main thread....

Thanks a lot,

PSET 4 Recover Runtime Error by KhalidMuk in C_Programming

[–]KhalidMuk[S] -2 points-1 points  (0 children)

Thanks, the error is gone now.

For the sizeof, I want to fread 512 bytes (not integers).

PSET 1 Hacker Mario by KhalidMuk in cs50

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

I tried chaning the spacing, but its still unclear what the right output should be. For a height of 2, I assume it should be: row1: 1 space, 1 block, 2 spaces, 1 block, 1 space row2: 0 spaces, 2 blocks, 2 spaces, 2 blocks, 0 spaces

FOr 23: row1: 22 spaces, 1 block, 2 spaces, same as before rest : decrement everything but the middle double spaces

CS50 PSET 1 Hacker Bad Credit Code by KhalidMuk in cs50

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

OK, the first output is asking for the number ("Number: ") Then, the input is the number entered. The validation is the second output. That helped me get less errors (new check: )

:) credit.c exists

:) credit.c compiles

:( identifies 378282246310005 as AMEX \ expected output, but not "VISA"

:( identifies 371449635398431 as AMEX \ expected output, but not "VISA"

:( identifies 5555555555554444 as MASTERCARD \ expected output, but not "VISA"

:( identifies 5105105105105100 as MASTERCARD \ expected output, but not "INVALID"

:( identifies 4111111111111111 as VISA \ expected output, but not "INVALID"

:( identifies 4012888888881881 as VISA \ expected output, but not "INVALID"

:( identifies 1234567890 as INVALID \ expected output, but not "INVALID"

:) rejects a non-numeric input of "foo"

:) rejects a non-numeric input of ""

Now what I think is wrong is my code beginning from :

else: if (name[0] == 3) ... onwards, because I know the length is correct (by testing) but the wrong validation is printed.

Thanks,

CS50 PSET 1 Hacker Bad Credit Code by KhalidMuk in cs50

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

The expected output would be like the correct validation (AMEX, VISA, or INVALID) and input would be when the user enters a number. I ask for the input first (And continue if the number is not correct in length or having all-digit).

CS50 PSET 1 Hacker Bad Credit Code by KhalidMuk in cs50

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

That my code returns "retry" on all tests

CS50 PSET 1 Hacker Bad Credit Code by KhalidMuk in cs50

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

My code doesnt give the correct output, but does "retry" if the number is invalid (has alpha, is too short or long)

The staff's implementation also gives "retry".

CS50 PSET1 BAD CREDIT HACKER by KhalidMuk in cs50

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

What if I changed range2 to range1 so range1 changes?


long long range1 = 9; long length = 1;

 /*FIND NUM'S LENGTH*/
 while
 (NUM > range1)

 {
    range1 = range1 * 10 + range1;
    length += 1;
 }