Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm not quite sure what is wrong with my current program and I have reach a bit of a road block:
(*ptr).Name = (char*)malloc(strlen(record+1));
strcpy((*ptr).Name, record);
free((*ptr).Name); //problem area
*ptr is a pointer that points to a structure that has various fields. After I copy some data into the Name field I want to free my allocated memory. When I step through my program I get no errors rather just a hanging program that will not continue after I try and free the memory. Any ideas? Thank you.
(*ptr).Name = (char*)malloc(strlen(record+1)); //This is the problem!
strcpy((*ptr).Name, record);
free((*ptr).Name); //problem area //Better practice to use free(ptr->Name
Fix:
ptr->Name = (char*)malloc(strlen(record)+1); //(record+1) in previouse code was doing
//the opposite of what it was intended to do
strcpy(ptr->Name, record);
free(ptr->Name);
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Given the following function:
image_ret* minify_1(image_src img_src, CLIENT* cl) {
image_ret* img_ret;
magickminify_init();
magickminify(img_src.image_src_val, img_src.image_src_len, (ssize_t*)&img_ret->image_ret_len);
return image_ret;
}
The compiler is telling me "expected expression before ‘image_ret’" with regard to the last line. I'm sure I'm missing some fundamental aspect of syntax here, but I don't know what. Lil' help?
You need to return a value, not a type. image_ret is a type, img_ret is a poitner to a value of that type and probably what you want to return, except I see nowhere in your code where you allocate any storage to it, or initialising any of the fields except image_ret_len
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Can someone tell me how should I do to allocate every v[i].word and next with NULL?
Struct hash{
Char*word;
Hash*next;
}*v[10];
Make a for loop, let it iterate from i = 0 to 9. In each iteration, allocate one struct hash and point v[i] to it. Afterwards, initialize *v[i] as needed. Don't forget to check if malloc() failed.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I coded like that, but it gets seg-fault.
What is wrong?
int vector_size = 100000000;
float *rows[vector_size];
for (int i=0; i<vector_size; i++) {
rows[i] = (float *)malloc(sizeof(float)*2); // crashed here
// ...
}
You are trying to allocate a vast amount of memory. If you really need this many floats, using a separate malloc for each one is probably a bad plan. Malloc has it's own overheads as there is a minimum block size that can be allocated, and the memory manager also needs to keep track of all those separately allocated areas of memory, not to mention the size of this list of pointers you are holding.
A better solution might be to allocate in a single block enough space for all floats, and the index as an array, rather then try and keep a list of pointers...
So...
float *rows = malloc(sizeof(float) * vector_size);
might be a better starting point.
Try to allocate memory not in the stack, but in a heap.
float **rows = new float*[vector_size];
And what message you get about crash?
It don't look like memory overflow, because if memory is ended malloc() returns NULL:\
P.S. sorry for my english)
upd. oh, i don't saw comments above
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm working on a scanner plugin that loops through a range of various channels in increments of up to 32.
I'm new to Lua.
Tables, tables everywhere.
I did not know Lua did not do +=, ++.
i = i + 1 -- flashbacks.
I'm running into this variable type error,
plugins/scanner/main.lua:136: 'for' limit must be a number
and i've checked my variable types. both say they're numbers.
right now i'm working on getting the incremental loops running smoothly.
here's the link to the code :
http://codepad.org/Dc3jBBrx
thanks again, stack.
I think it's probably just a typo on line 136
Scanner.innerRrangeMax should be Scanner.innerRangeMax
e.g line 136 is
for i = Scanner.innerRangeMin, Scanner.innerRrangeMax do
try
for i = Scanner.innerRangeMin, Scanner.innerRangeMax do
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
I am making a C program that is a simple calculator without a GUI, called "Quical". (Check out the code on Github). I am somewhat new to C, and so I am making some syntax errors. One of the errors is this:
expected declaration or statement at end of input
Another one of the errors that comes up is this:
else without a previous if
Here is my code.
Hopefully, this can shed some light as to why I am getting these syntax errors. Any help would be much appreciated.
Your braces don't match. You have something like
main()
{
some statement
{
}
another
{
}
and it ends.
It is saying it wants a statement here. Try that and see what the next error is.