Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

acessing a 1D array with row/col

Name: Anonymous 2009-04-21 8:27

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: Anonymous 2009-04-21 8:32

What makes you think this isn't right?

Name: Anonymous 2009-04-21 8:33

It's right. Although a variable called imagePtr is pretty dumb.

Name: Anonymous 2009-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: Anonymous 2009-04-21 8:37

entire sample

image_ptr negateImage(image_ptr imagePtr, int rows, int cols, int maxval)
{
    int i,j;
   
    for (i=0; i<rows; i++)
    {
        for (j=0; j<cols; j++)
        {
            printf(" %d", (i*cols + j));
            imagePtr[i*cols + j] = abs((imagePtr[i*cols + j]-maxval));
        }
    }
}

Name: Anonymous 2009-04-21 8:38

Please stop.
This really isn't a homework help forum.

Name: Anonymous 2009-04-21 8:39

abs((imagePtr[i*cols + j]-maxval));
what the shit

Name: SAGEFAULT 2009-04-21 8:40

SAGEFAULT

Name: Anonymous 2009-04-21 8:48

>>7
it's supposed to be the negative of the grey scale color pixel value stored in (i,j), where maxval is the maximum value of the scale.

Name: Anonymous 2009-04-21 8:55

Whatever's causing your memory access violation isn't visible in that code. Check the part where you're allocating imagePtr.

Name: Anonymous 2009-04-21 8:56

>>9
That was not my issue, sir

Name: Anonymous 2009-04-21 8:57

ITT we can't handle a new/malloc and try to rewrite Photoshop from scratch anyway

Name: Anonymous 2009-04-21 9:03

Name: Anonymous 2009-04-21 9:04

>>11
then what were you trying to say?

Name: Anonymous 2009-04-21 9:09

image_ptr negateImage(image_ptr imagePtr[], int rows, int cols, int maxval)

Name: Anonymous 2009-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: Anonymous 2009-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.

Name: Anonymous 2009-04-21 10:26

ITT we don't know the difference between rows and columns.

And between pointers and arrays, though that's not the issue here.

Name: Anonymous 2009-04-21 10:32

>>18
It seems you're the only one here who doesn't know the difference between rows and columns.

Name: Anonymous 2009-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!

Name: Anonymous 2009-04-21 11:10

>>20
works now
No, it doesn't.

Name: Anonymous 2009-04-21 11:22

>>21
uh, what? the problem i was having is solved...

Name: Anonymous 2009-04-21 11:37

>>22
You don't understand what your problem was. You've done something that seems to work, and think you've solved it.

There is a name for this kind of asshattery.

Name: Anonymous 2009-04-21 11:41

>>23
Shhh.  As long as he believes it, at least our problem is solved.

Name: Anonymous 2009-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: Anonymous 2009-04-21 12:04

>>17
Couldn't agree more, it's people like >>4 who perverted hungarian notation.

Name: Anonymous 2009-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: Anonymous 2009-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).

Name: Anonymous 2009-04-21 12:46

Holy dicks.

----------
Posted from my TI-89

Name: Anonymous 2009-04-21 13:10

imagePtr=(image_ptr) image;
Bwahahahahaha so clueless...

Name: Anonymous 2009-04-21 13:32

>>30
yeah i caught that. should be return, obviously.

Name: Anonymous 2009-04-21 17:22

>>31
This is getting silly, Mr.Troll.
I refuse to believe you are a genuine idiot you pretend to be.

Name: Anonymous 2009-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/.

Name: Anonymous 2009-04-22 6:53

>>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: Anonymous 2009-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

Name: Anonymous 2009-04-22 11:32

Stop programming. Now and forevermore.

Name: Anonymous 2009-04-22 11:44

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: Anonymous 2009-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.

Name: Anonymous 2009-04-22 11:54

and want world to know.

Name: Anonymous 2009-04-22 11:59

>>20
imagePtr=(image_ptr) image;
Wow. What is that supposed to do?

Name: Anonymous 2009-04-22 12:11

>>1-40
YHBT

Name: Anonymous 2009-04-22 13:07

>>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.

Name: Anonymous 2009-04-22 13:10

>>40
I never heard of casts.

Name: Anonymous 2009-04-22 13:32

(int) hax my anus!

Name: Anonymous 2009-04-22 13:37

>>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 :(

Name: Anonymous 2009-04-22 14:01

>>45
Fuck hax my anus! You hax my anus!.

Name: Anonymous 2009-04-22 14:03

:(
IHABT

Name: Anonymous 2009-04-22 14:04

>>47
IHABT
HMA

Name: Anonymous 2009-04-22 14:25

>>48
HMA my anus!

Name: Anonymous 2009-04-22 16:40

Please stop BUMPING. OP has been proven to be a retard.

Name: Anonymous 2009-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;

Name: Anonymous 2009-04-23 11:45

>>51
*as i abs()'d the result anyway

Name: Anonymous 2009-04-23 11:49

return((image_ptr)image); vs return (image_ptr)image;
LOL I can't believe you didn't fix this earlier.

Name: Anonymous 2009-04-23 12:02

OP here, I'm a massive faggot.

Name: Anonymous 2009-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...

Name: Anonymous 2009-04-23 14:30

>>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: Anonymous 2009-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: Anonymous 2009-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: Anonymous 2009-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: Anonymous 2009-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

>>59
you just got trolled

Name: Anonymous 2009-04-23 15:48

>>60
What are you, 12?

Name: Anonymous 2009-04-23 19:57

>>61
Color me moderately amused.

Name: Anonymous 2013-04-20 17:57

Name: Anonymous 2013-04-20 23:29



Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop

Don't change these.
Name: Email:
Entire Thread Thread List