Your problem is here:
while (fread(buffer, 512, 1, filein)==1)
//if no jpg found and no jpg id then skip
if (i == 0 && buffer == 0 && buffer == 0 && buffer == 0 && buffer == 0)
// check if buffer has either key jpg strings
else if (buffer == 0xff && buffer == 0xd8 &...
Issues with your program:
First, you're reserving 10 chars for the name of the JPG while the maximum length of the name of any JPG is just 7 (e.g., 0xy.jpg) + 1 for the null terminator (i.e., '\0').
Second, within your for loop
for (int i = 0; i < BLOCK; i++)
fread(&buff[i], sizeof(BYTE), 1, card);
you're reading 512 bytes, but you're ...
Thankfully I found where I have done a mistake!
It's in the initScoreboard . I didn't add return scoreboard to be used in updateScoreboard because in the beginning of main there's GLabel label=initScoreboard and that must have a return value!
Thank you for your help ^^
You have popped with many questions at the same time. Lets start with the simplest one.
What's the relation between return value of a function and command line arguments?
You don't return 1 because you have 1 command line argument. The return value of any function(including main()) is almost independent of the arguments passed (unless you do something ...
Your code has several issues. First, you're hitting the seg fault because you are trying to close a nonexistent output file when you hit the first signature.
Second, you're declaring img twice ( FILE * img... ). Since the second time occurs inside of a set of curly braces that don't contain the first declaration, the compiler creates a local version of img ...
I was having a similar problem when I moved from:
if (object == paddle)
if (strcmp(getType(object), "GRect") == 0)
After reading your question, I realized I was probably not handling NULL correctly, and so I went back and did a check to make sure the object being returned by getCollision was not equal to NULL. Then, things worked better. In your ...
One of the skills that are indirectly taught in this class, as well as being one of the most important skills you must learn as a programmer is how to debug a program. You will run into seg faults frequently as a programmer, so you really need to learn how to isolate them yourself!
There are a number of techniques you can use. You could step through the ...
isblank(_), like isupper() and islower(), takes a single character as an argument. You are passing it an entire string and it's choking on it, causing a seg fault. isblank(name[i]) solves the issue nicely.
Also, I don't follow the reason for i++; inside the if loop. The for loop is incrementing i, so do you really want to increment it again inside the loop?...
int k = atoi(argv);
if (argc != 2)
You are assuming that argv  exists before checking that really exists, if we have more than two arguments your program will work well, but if you have only one argument are accessing a memory area to which you should not access and argv  "does not exist" hence your segmentation fault
Si esto responda ...
The root cause of your seg fault is this:
char * nameoffile = "";
When you create a string in memory, the space allocated is fixed at that time. In this case, you created a string of length 0 plus the end of string marker. Later, when you try to create the filename with the sprintf() call, the code tries to insert a longer string into this space, ...
You did a pretty good job of narrowing the problem down!
The isupper() function (and all it's cousins) takes a single char as input, but argv is a string, not a single char. The line of code tries to shove a string down isupper()'s throat, so it chokes and throws a seg fault. You need to process one char at a time through isupper()....
This is a very, very common error for new programmers. The problem is the actual call to isalpha(). The isalpha() function takes a single char as input, but argv is a string, not a char. Simply put, the code is trying to stuff a string down isalpha's throat and it chokes, resulting in a seg fault.
You need to check each char in the string. Hint: a for ...
First, you really, really need to learn how to determine which line is generating a seg fault in any program! Seg faults are going to occur over and over and over. This is one of the most critical skills - identifying which line causes a problem!!!! I can't stress this enough!!!!
There are two common ways to track down a seg fault. One is to run the ...
You're trying to read 2 elements of size 512 bytes into a buffer which I assume is of size 512 bytes only. That's definitely one reason why your program segfaults.
Also, fread() returns the number of bytes that were successfully read if the number of elements is 1. I don't really know why you're checking whether the return value is not equal to 1 in this ...
isalpha() works on a char, and you've given it a string. That will segfault. You need to check each individual char, so think of using a loop.
To run in gdb:
(gdb) run abc
will run it with key of abc
The string argv refers to string of strings. So when you are trying to do argv then it means that you are looking for a string, but you cannot use isalpha(string), because the argument passed to isalpha() is char. It should be like isalpha(argv), where argv refers to the first character in the second string in the list of strings.
What type have you initialized the variable "collision" to be? If you initialized it as a string, that could be the issue.
Make sure you are initializing it as:
GObject collision = detectCollision(window, ball);
It turns out that isalpha is defined as a macro in the ctype.h header file, in my case, according to this answer (by @ouah on Stack Overflow):
Add -Wsystem-headers to get the warning
From gcc documentation (emphasize mine)
Print warning messages for constructs found in system header files. Warnings
from system ...
First, strcat doesn't work because of the fact that the string literal "a" that's stored in s is stored into a read-only-data section in memory. So you cannot modify its contents.
A simple fix to that is to use a char array that's big enough to fit the concatenated strings as well as the null terminator. So
should work ...
Make the array checkw the size of the global variable LENGTH + 1 to ensure you have an array that can hold all words. Also create a variable to store the length of word, repetitive calls to strlen is bad practice.
So your code should look like such:
char checkw[LENGTH + 1];
int len = strlen(word);
for (int i = 0; i < len; ++i)
checkw[i] = ...
It clearly doesn't like the tests in the if statement, buffer == (char)0xff seems to be making it choke. There's an easy fix that makes it work though. Change the declaration of your buffer. Instead of
char* buffer = malloc(512);
change it to
This will make your test conditions work. Also, you'll need to delete the free(...
You are getting segfault because you are declaring a char* buffer = malloc(512) which is your pointer to a block of 512 bytes of memory. But later, when you read in the bytes, you are reading into &buffer which is the address that holds the pointer to the 512 bytes. It can't hold 512 bytes itself, so you segfault.
Change your fread to fread(buffer ......
Your problem is isalpha(argv) isalpha takes a single character as input. argv is a string of multiple characters, not a character. You cannot apply isalpha to an entire string. It causes a seg fault.
If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ...