Hot answers tagged

18

When you open a file a cursor is set somewhere in it (look at man fopen for more about that) and you can change this cursor position using fseek. When you read a "block" (in your case you read sizeof(RGBTRIPLE) bytes) from your file using fread the cursor will be move forward automatically by sizeof(RGBTRIPLE) bytes since your cursor needs to be on each ...


5

how does freed know to read one byte after another? It's essentially the definition of fread(): size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr. In your example fread(&triple, sizeof(...


3

In the demo code that merely copies a bitmap, they are demonstrating how to strip off the padding and then add it back when writing to the outfile because that ability will be needed later. Yes, every scan line has padding at the end because each line needs to end on a 4-byte boundary. Keep that in mind because when you are scaling the image up to a ...


3

Without reviewing your code, let me try to explain. Yes, you've got the idea. fread() does cause the file pointer to track location. Let's say you have a file pointer called inptr. Next, let's say that inptr is pointing at byte 100 in your file. You issue an fread(&triple, 3, 1, inptr); command. This says read 1 block of 3 bytes - a total of 3 bytes. ...


2

fputc(0x00, output); really puts a single char. 0x00 in hexadecimal is exactly one byte. the 0x is not part of the number, it just indicate that the number is in fact hexadecimal. Would be good clarify that, the padding in the example image is really == 1 (1 byte), at the end of each scanline. Since there are 3 vertical lines so there are a total of 3 ...


2

What it does, Kareem, is it puts one byte with every iteration of the loop. padding is equal to 3 (i.e., 3 bytes) in this case! :)


2

Because you are creating c as an array of strings. I think you meant to make c an array of n chars. Remember that a string is an array of chars in which the last char is a null terminator \0. I suggest you change this line: string c [n]; to: char c[n]; Since you are printing c character by character you don't need to add the null terminator at the end. ...


1

char* t = malloc(strlen(s)+1) * sizeof(char); this is wrong, we can not multiply a pointer with an integer, as the error says multiplication operators are not compatible,the correct way would be char* t = malloc((strlen(s)+1) * sizeof(char)); Second: t[0]= toupper; what it is toupper? I suppose you want to use the toupper function, the correct way to ...


1

malloc() is declared in <stdlib.h>, so you must include that. I believe adding the stdlib header will fix your second error as well, since t[0] doesn't actually exist as the call to malloc() failed, however if it didn't fix it, feel free to message me back! Edit: Mars's answer is much better, follow his advice, although you still need to include ...


1

At the top taskbar, under "Devices" go to "Shared Clipboard" and adjust the settings. You can use the clipboard function to copy to or from the guest (in CS50, the appliance) to your computer. Options are from guest to host, from host to guest, or bidirectional.


1

As you mentioned on this post: How do I enlarge my appliance? This answer: https://cs50.stackexchange.com/a/14519/7276 solves this problem too. Cheers!


1

For Hypervisor: This feature should be enabled by default. Maybe you turned it of accidentally. Choose Edit > Preferences. On the Input tab, set the check box beside Enable copy and paste to and from virtual machine.     Link to vmware docs For VirtualBox: You must explicitly enable it by going to |General|Advanced and setting Shared ...


1

fread() knows nothing about the structure. All it knows is the size of the block to read and the address of the memory block where it will put the bytes it reads. It's up to you to make sure that the block of data you're reading in is sensible and matches the structure that you will subsequently use to access the individual members of the BITMAPFILEHEADER ...


1

This is a late answer but is relevant as I feel that the actual question was not answered. I had the same question and while searching for answer reached this post."why is copy.c skipping over padding? Then why and how is it able to add it back to the bitmap?" fseek has been already explained. The inptr (from fopen) is skipping the padding (inptr after ...


Only top voted, non community-wiki answers of a minimum length are eligible