access violation

hi,

i know this topic has been discussed so many times you probably want to kill me for bringing it again. I tried my best not to bother anyone but without success..

why is this throwing AV?

1
2
3
4
char *args[14];
...
args[argc]=new char[i-last_arg];
args[argc][i-last_arg]=0;


it's ok until it's third time coming over the line which sets last char in the array to zero. i have checked all the numbers and it's all in bounds. argc is 2 and i-last_arg is 1. commenting that one line makes it work without AV but i need the strings to be ended :(
Last edited on
Why are you accessing it as a 2-dimensional array in that line? Maybe a refresher course in Arrays would be helpful for you.
Uh? what's wrong with that? you can use index for dereferencing a pointer.. or what do you mean? I know i shouldn't access the last element but how else do i get the zero in there?
Last edited on
ok... I'll just make it one byte longer, but it sucks
To me it looks like this line:
args[argc][i-last_arg]=0;
is referencing args as a 2-dimensional array args[][], but it's only a one dimensional array args[].

Maybe I'm wrong here, but I think that's your problem.
ummm.. it's array of pointers each pointing to arrays of chars. first dereferencing returns address the next one returns value in array. it is ok
args[argc][i-last_arg]=0; //array out of bounds access error

the actual array values are 0 to ( i-last_arg)-1
oh... well.. that's.. :D .. good to know it at least.. thx
Topic archived. No new replies allowed.