Link to home
Start Free TrialLog in
Avatar of btocakci
btocakciFlag for Türkiye

asked on

pointer arrays

Hi! im trying to use one of the elements of an pointer array like *ptrarray[10] in strcopy function..

....
atomptr=strtok(string,"");

for(i=0;i<10;i++){
strcpy(ptrarray[i],atomptr);
atomptr=strtok(NULL;"");}


my goal is to put all of the atoms of a string into seperate strings..
....

but it doesnt run..What is the mistake here?..
Avatar of sunnycoder
sunnycoder
Flag of India image

Hi btocakci,
> atomptr=strtok(NULL;"");}
there should be a comma (,) and not semi-colon between NULL and "" 
atomptr=strtok(NULL,"");}

> but it doesnt run..What is the mistake here?..
What are the errors? Does the above rectify them?

Cheers!
sunnycoder
Avatar of btocakci

ASKER

"proje.exe has encountered with a problem and must be closed.." sayin window was opened and program was closed..

i encounter with no errors or warnings in microsoft Visual studio compiler..
Hi btocakci,

This sounds like you are accessing some memory which you should be accessing or there is some logical error.

If the code is small, post it here and we will have a look at it. If the code is huge, try to run it through a debugger or place prints at several places to find out where the error is occuring

Cheers!
sunnycoder
     atomptr=strtok(string,sep);


      i=0;      
      while((strcmp(atomptr,from))){
      
            printf("%s\n\n",atomptr);
            
                        atomptr=strtok(NULL,sep);

                        strcpy(selectarraytemp[i],atomptr);
      i++;
      }
      
      strcpy(selectarraytemp[0],talha);

want to put this atoms into strings while the word "from" encountered. May tyhere be any infinite loops?
of course i wrote char*from="from" at the beginning..
Avatar of grg99
grg99

have you initilized ptrarray's elements to point to some char[] array memory?

i think i dont know how to do this?!
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
really thanks sunnycoder, i have really much to learn from you..

error C2440: '=' : cannot convert from 'void *' to 'char *'
        Conversion from 'void*' to pointer to non-'void' requires an explicit cast

on the line :       selectarraytemp[i] = malloc (strlen(atomptr)+1);

what may be the problem?
Try to use the hints in error messages and warnings to determine what the problem might be ;)
selectarraytemp[i] = (char *)malloc (strlen(atomptr)+1);
You will really teach me how to code in c by just yourself i think..Really thanks..
Glad to help :)