Skip to main content
replaced http://cs50.stackexchange.com/ with https://cs50.stackexchange.com/
Source Link

I'm pretty sure the problem is in "load" (but, I could be wrong). I know it is tricky to write user input to pipe, but, if we could read bytes and store it in *content & *length, shouldn't there be a way (an easy one, I hope) to write into it? I've looked around for ideas from the forum, but it remains unclear. Here's a postpost where this problem was also mentioned.

I'm pretty sure the problem is in "load" (but, I could be wrong). I know it is tricky to write user input to pipe, but, if we could read bytes and store it in *content & *length, shouldn't there be a way (an easy one, I hope) to write into it? I've looked around for ideas from the forum, but it remains unclear. Here's a post where this problem was also mentioned.

I'm pretty sure the problem is in "load" (but, I could be wrong). I know it is tricky to write user input to pipe, but, if we could read bytes and store it in *content & *length, shouldn't there be a way (an easy one, I hope) to write into it? I've looked around for ideas from the forum, but it remains unclear. Here's a post where this problem was also mentioned.

edited tags
Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17
academic honesty compliance
Source Link
bool load(FILE* file, BYTE** content, size_t* length)

{

    // declare variables
    *content = NULL;
    *length = 0;
    BYTE buffer[BYTES];
    
    if(file == NULL)
        return false;
        
    // iterate over file, bytes by bytes
    for(int c = fread(buffer, 1, BYTES, file); c != 0; c = fread(buffer, 1, BYTES, file))
    {
        *content = realloc(*content, *length + c + 1);
        if(*content == NULL)
            return false; 
        memcpy(*content + *length, buffer, c);
        *length += c;
    }
    return true;    
}

Code removed per academic honesty<<

bool load(FILE* file, BYTE** content, size_t* length)

{

    // declare variables
    *content = NULL;
    *length = 0;
    BYTE buffer[BYTES];
    
    if(file == NULL)
        return false;
        
    // iterate over file, bytes by bytes
    for(int c = fread(buffer, 1, BYTES, file); c != 0; c = fread(buffer, 1, BYTES, file))
    {
        *content = realloc(*content, *length + c + 1);
        if(*content == NULL)
            return false; 
        memcpy(*content + *length, buffer, c);
        *length += c;
    }
    return true;    
}

Code removed per academic honesty<<

added 218 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17
Loading
adding parse and check50 server1 result
Source Link
Loading
added 92 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17
Loading
Source Link
Loading