imagePtr[i*cols + j]
where i and j are the row/col coordinates. this isn't right, i can't remember how else to do it. i know it's something LIKE this, just not exactly what, and google isn't cooperating. do i need to use the memory locations?
Name:
Anonymous2009-04-21 8:32
What makes you think this isn't right?
Name:
Anonymous2009-04-21 8:33
It's right. Although a variable called imagePtr is pretty dumb.
Name:
Anonymous2009-04-21 8:36
>>2
it doesn't work. memory access violation >>3
mandated
it's actually a pointer, did i do something wrong there? do i need to dereference it or something?
Name:
Anonymous2009-04-21 8:37
entire sample
image_ptr negateImage(image_ptr imagePtr, int rows, int cols, int maxval)
{
int i,j;
image_ptr negateImage(image_ptr imagePtr[], int rows, int cols, int maxval)
Name:
Anonymous2009-04-21 9:20
So, you're either overflowing your buffer, or your buffer is not of the right size. ( it should be of size cols*rows )
You didn't provide us enough code for us to be able to fix your problem, but fear not, as you can probably solve it yourself. Get a debugger! Run the application and see where it breaks, or set a breakpoint on the faulty line(which you already know), set a breakpoint on where you alloc the picture buffer as well, after this, such simple errors become apparent, but if that wasn't enough, you may post the full code and maybe some kind anon will help you, but you really shouldn't rely on that!
Name:
Anonymous2009-04-21 9:22
>>4 it's actually a pointer, did i do something wrong there?
Yes, you gave it a dumb name. Although image_ptr imagePtr is even worse.
ITT we don't know the difference between rows and columns.
And between pointers and arrays, though that's not the issue here.
Name:
Anonymous2009-04-21 10:32
>>18
It seems you're the only one here who doesn't know the difference between rows and columns.
Name:
Anonymous2009-04-21 10:49
, /prog/, >>10 and >>16 had it right, sorta. it turns out img_ptr actually isn't just a 1D array as i had thought, or something. anyway
image_ptr negateImage(image_ptr imagePtr, int rows, int cols, int maxval)
{
int i,j;
unsigned char image[rows][cols];
for (i=0; i< rows; i++)
{
for (j=0; j< cols; j++)
{
image[i][j] = abs((imagePtr[i*cols + j]-maxval));;
}
}
imagePtr=(image_ptr) image;
}
works now. or at least it doesn't crash and it obviously messes with the image, only question now is how to actually get the inversion working. i had thought what i had would work (it's for .pgm files), but it isn't. i can figure it out i'm sure, thanks again!
>>23
Shhh. As long as he believes it, at least our problem is solved.
Name:
Anonymous2009-04-21 11:41
>>23
You talk a whole lot of shit without giving any information about the problem. Your posts are general enough that they could apply to anything.
Name:
Anonymous2009-04-21 12:04
>>17
Couldn't agree more, it's people like >>4 who perverted hungarian notation.
Name:
Anonymous2009-04-21 12:15
>>25
"My posts"? What are you, an EXPERT EXTRAPOLATOR?
The information given doesn't make more specific help possible. I'm just telling you that you're making the grave error of mistaking "it seems to work" for "it works". This just shows you're very inexperienced in C. If you want to act all pissed off at someone offering genuine help, be my guest. You've already failed at life.
----------
Posted from my iPhone
Name:
Anonymous2009-04-21 12:39
>>27
my apologies if i have misinterpreted your intentions (which i honestly still don't think i have), i'm used to elitist faggotry and disinformation/aggravation from /prog/. it is working as i expected (more or less), and i know what i was doing wrong (trying to use the image_pointer structure as an simple array of unsigned int/char when in reality writing to it is not possible as so).
>>31
This is getting silly, Mr.Troll.
I refuse to believe you are a genuine idiot you pretend to be.
Name:
Anonymous2009-04-21 21:03
>>32
what's wrong with it? the casting? it may be unnecessary, but is it not proper programming practice to do it anyway? go fuck yourself, this is the kind of stupid elitist circlejerking that i've come to expect from /prog/.
>>33 go fuck yourself, this is the kind of stupid elitist circlejerking that i've come to expect from /prog/.
I'll give you a hint.
Nobody wants to help you because you're doing stupid and boring shit a 5 year old would figure out. If you can't spend enough effort to read a book on basic C then that's your problem.
go fuck yourself, this is the kind of stupid elitist circlejerking that i've come to expect from /prog/.
Stop acting like a child.
Name:
Anonymous2009-04-22 11:24
OP here, I apologize for that outburst, I don't know what came over me. Now, if you'll just answer my question everything will be fine
OP here, I apologize for that outburst, I don't know what came over me. Now, if you'll just leave me to suck a billion cocks everything will be fine
Name:
Anonymous2009-04-22 11:50
Do it twice. Call this function with two different pictures. Then you'll understand that whatever you're doing is wrong and you're not getting any ``disinformation from (unspoilered)/prog/''. This is such a basic problem that having people who don't even know about it post on our nice textboard is very embarrassing. Please go away. We don't want your kind here. There is that stack overflow forum and many other web 2.0 websights full of people who just learned about this and want world to know.
>>35
I don't give a shit. GO READ A MOTHERFUCKING BOOK. If you can't be arsed to do that little then programming is not for you (in C especially, [prog]PHP[/prog] maybe). Go to some rentacoder site and hire someone to write it for you.
>>43
No you fucktard. I wondered what the fuck does he want to accomplish by overwriting a local variable at the end of the function. Not to mention that the memory at image wasn't even allocated using new/malloc. Also, IHBT:(
PleasestopBUMPING. OP has been proven to be a retard.
Name:
Anonymous2009-04-23 11:34
op here, returning after >>33 (anyone purporting to be me after that point was just imitating). you are all a bunch of faggots. the problem was the maxval variable coming in as 448 instead of 256, due to my skipping over of two getnum() calls.
anyone know why this would cause a fucking segfault? i can't figure it, especially as i maxval'd the result anyway. it really does work now, produced exactly the desired results with just adding two 'getnum(*fp);' to the function that had been responsible for getting the maxval (otherwise it is the same code as in >>20, with the return fixed). one thing i did was couch the cast in addition brakcets but i don't think that would actually have any effect (was kinda desperately testing everything, which is when i did the printf("%d", maxval) and saw the problem). like return((image_ptr)image); vs return (image_ptr)image;
return((image_ptr)image); vs return (image_ptr)image;
LOL I can't believe you didn't fix this earlier.
Name:
Anonymous2009-04-23 12:02
OP here, I'm a massive faggot.
Name:
Anonymous2009-04-23 12:17
>>53
is that really what was causing it? i thought return had to evaluate all attached operands first? and what is a cast anyway, isn't it an operation (how would you return it)? and none of it explains how the function was able to get partial operation...
>>51 anyone purporting to be me after that point was just imitating
Riiight. anyone know why this would cause a fucking segfault?
Because you're still an idiot.
Name:
Anonymous2009-04-23 15:29
no one on /prog/ actually knows anything. this isn't a gauntlet, it is what i have determined after visiting a few times and making a few posts.
Name:
Anonymous2009-04-23 15:34
>>57
BULLSHIT, I, for one, know how to to write:
* factorial
* fibs
* Löb
* an ANSI C compiler in ANSI C
Name:
Anonymous2009-04-23 15:35
>>57
you just don't get /prog/. But let me enlighten you, I come here to troll and to generally act like an idiot. It's a great way to relax after a hard days coding. The reason no-one helps anyone is because the majority of problems posted here are trivial and solvable by not being an idiot (this may or may not include using google). If after ``visiting a few times '' you don't get that, you shouldn't be here or anywhere else on the internet (except maybe /pr/)
tl;dr
Like it or lump it
Name:
Anonymous2009-04-23 15:44
>>58 an ANSI C compiler in ANSI C
i'm actually taking this course next semester, very much looking forward to it