Re: [Dev-C++] elements from an array of pointers...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2002-10-28 19:55:11
|
Well, your questions are still about school assignments, even if you
now have removed any comments to your teachers requirements, but...
Might you tell us how you expected the "mystring" parameter to pop and
temp_pop to actually return anything to the caller? Yes inside your
function, mystring is a variable like everything else. Then you assign a
new pointer to the parameter, and copy a string value to the newly
allocated buffer space.
/Per W
On Mon, 28 Oct 2002, senem beken wrote:
>
> when i try to get the elements back from a function i wrote, i get an error called "access violation" and i don't know what that is.i'd be glad if anyone who has time would look at it...i'm sending one part of the code, the one which doesn't work...
> kind regards...
> int removecar(int garagenum,char *mystring){
> int i=0;
> char plaka[10];
> if(garagenum==1){
> while(strcmp(garage1.plate[i],mystring)==0){
> pop(plaka,garage1);
> push(plaka,temporary);
> i++;
> }
>
> while(isempty(temporary)!=1){
> pop(plaka,temporary);
> push(plaka,garage1);
> }
> temp_pop(plaka,garage3);
> push(plaka,garage1);
> return 1;
> }
> if(garagenum==2){
> i=0;
> while(strcmp(garage2.plate[i],mystring)==1){
> pop(plaka,garage2);
> push(plaka,temporary);
> i++;
> }
>
> while(!isempty(temporary)){
> pop(plaka,temporary);
> push(plaka,garage2);
> }
> temp_pop(plaka,garage3);
> push(plaka,garage2);
> return 1;
> }
> if(garagenum==3){
> if(findel(garage1,mystring)){
> while(strcmp(garage1.plate[i],mystring)==1){
> pop(plaka,garage1);
> push(plaka,temporary);
> i++;
> }
>
> while(!isempty(temporary)){
> pop(plaka,temporary);
> push(plaka,garage1);
> }
> return 1;
> }
> if(findel(garage2,mystring)){
> while(strcmp(garage2.plate[i],mystring)==1){
> pop(plaka,garage2);
> push(plaka,temporary);
> i++;
> }
>
> while(!isempty(temporary)){
> pop(plaka,temporary);
> push(plaka,garage2);
> }
> return 1;
> }
> if(temp_findel(garage3,mystring)){
> temp_pop(plaka,garage3);
> return 1;
> }
> if(!temp_findel(garage3,mystring)&&!findel(garage2,mystring)&&
> !findel(garage1,mystring))
>
> return 0;
> }
> }
>
> void pop(char *mystring,garage &line){
> if(isempty(line)){
> cout<<"error,can't pop,stack empty"<<endl;
> exit(1);
> }
> else{
> line.top--;
> mystring=new char[sizeof(line.plate[line.top])/sizeof(char)];
> strcpy(mystring,line.plate[line.top]);
> line.elements--;
> }
> }
> void temp_pop(char *mystring,temp_storage &line){
> if(temp_isempty(line)){
> cout<<"error,can't pop,stack empty"<<endl;
> exit(1);
> }
> else{
> line.temptop--;
> mystring=new char[sizeof(line.tempplate[line.temptop])
> /sizeof(char)];
> strcpy(mystring,line.tempplate[line.temptop]);
> line.tempelements--;
> }
> }
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Y! Web Hosting - Let the expert host your web site
|