Hot answers tagged

8

The immediate problem lies with your header structures. You have created bi_new and modified two of it's fields, but you forgot to copy the contents of bi to bi_new, so all of the unmodified fields contain garbage data. This is why you're getting the unsupported image error. FYI, whole structures can be copied at once simply by a=b; so that you don't have ...


3

Actually, the program is working exactly as designed. Unfortunately, it isn't what you think. ;-) If you run the program, it will essentially copy the input file to the output file. Along the way, it will print each char that is read. The reason for your confusion is that you're expecting it to printf what you see in the file. Because of the formatting ...


2

FILE* img = fopen(title, "w"); // SEGMENTATION FAULT OCCURRING REALLY HERE This is because char title [3] does not have enough space to store the title, change it to char title [8] for example


2

There are several issues and areas for improvement here. First, there's this: FILE *f = fopen("argv[1]", "r"); By putting argv[1] in quotes, you're saying to treat whatever is in quotes as a literal string. In other words, open a file named "argv[1]". Remove the quotes to use the string/filename contained inside argv[1]. That ...


1

The fread and fwrite functions are working fine, as expected, the problems are elsewhere, a somewhat more coherent way of writing your program will be the following: #include <stdio.h> #include <stdint.h> #include <stdlib.h> typedef uint8_t BYTE; int main(void) { FILE* open = fopen("open.txt","r"); BYTE read[10]; FILE* ...


1

Your you are very close to the solution. The most serious problem of this program is the padding: fseek(inptr, -(bi.biWidth + padding), SEEK_CUR); your value is not correct, but nearly. note that biWidth is the width in pixels, which is made each three bytes (if I remember correctly) in an uncompressed bmp. for (int i = 0, biHeight = abs(bi.biHeight); i &...


1

Based on the fact that you only posted code that relates to query, you solved your indexes problem. Good on ya. I'll try to be the "human gdb" for the query code. But really, command line gdb is much more reliable :) Find tips here. I have to assume cursor is != NULL here if(cursor != NULL), because the test that failed was hello.php?name=Alice. It's ...


1

The problem is that the code has a memory overwrite problem that is corrupting data while it's being processed. It's very subtle and easily missed. char title[7]; Since title is only 7 chars long, it doesn't allow room for the end of string marker. When a file name is created, the end of string marker, \0, is being written beyond the end of the array. It ...


1

I didn't to a thorough analysis, but I did see a few things and have some thoughts. First, the signature test will pass any value for the 4th byte. Because of the or clause, (s[3] <= (char)0xef || s[3] >= (char)0xe0) it's like saying x <= 5 OR x >= 2, which is any number. After that, are you sure that it is finding signatures? Maybe a printf in ...


1

a text file is a stream of individual characters, not strings. the way you read/store a group of these chars, from the file, totally depends on you. for example, you may wanna read collectively or one by one. you may wanna and store them in a char array (not terminated with '\0') or a string (terminated with '\0'). you may wanna interpret them differently ...


1

From man fread (emphasis added): On success, fread() and fwrite() return the number of items read or written. This number equals the number of bytes transferred only when size is 1. If an error occurs, or the end of the file is reached, the return value is a short item count (or zero). fread signature is size_t ...


1

According to your code's logic, a new file will be opened and be written with 512 KB data each time it finds the specific header. Your program won't write any other 512 KB chunks to the file because the condition isn't satisfied. It simply skips until a new file is opened. Try tweaking a bit. Also, you're only checking two headers: 0xff, 0xd8, 0xff, 0xe0 ...


1

Can you say "typo = infinite loop" ? // replicate pixel n times to outfile for(int l = 0; l < n; i++) { fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr); } Your for loop initialized L but then increments I (caps added for visibility), resulting in an infinite loop that just keeps writing ...


1

I think the issue is that all of your nodes' word elements are pointing to the same chunk of memory. Let's take a look. In main() you ask for a new pointer with this line: char* word = malloc(sizeof(char) * 45); Then, each time you execute the fscanf() in your while loop, you go to the memory that word points to and update it with the next string from ...


1

I really don't understand it very well myself but i am going to try explain it. It is all related to the way this values are stored in the memory, RAM, hard drives, ..., integers, decimal numbers, hexadecimal numbers, ascii characters and more, at the end all are converted to binary in order to be stored in memory, only 0's and 1's. For example: The ascii ...


1

It can't be bfType = 0x424d because that is a completely different number. Yes, it would surely be a different value if it was interpreted as a whole and compared it with each of the 0x42 and 0x4d separately. But what technically happens is something like this /* imagine this is the memory */ b0 b1 b2 b4 ... [0x42][0x4d][....][....] ... ...


1

I don't think that's how booleans work. It looks like you are trying to declare a function that evaluates to True if the .jpg file header is found. Try using an if statement instead. if((buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff) && (buffer[3] == 0xe1 || buffer[3] == 0xe0))


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