IcePickLobotomy

makeargs method.

May 11th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. char ** makeargs(char *s, int * argc) //argc is num of strings to make in the array, s is the full string, need to break up.
  2. {
  3. strip(s);
  4. char sCopy[MAX], temp[MAX]; // = (char*) calloc(strlen(s) + 1, sizeof(char));
  5. int count = 0, x = 0;
  6.  
  7. strncpy(sCopy,s,strlen(s) + 1);
  8.  
  9. printf("s = %s, sCopy = %s\n", s, sCopy);
  10.  
  11. strncpy(temp,strtok(sCopy, " "), MAX);
  12. count++;
  13. printf("TEMP IS: %s at count %d | ", temp, count);
  14.  
  15.  
  16. while(sCopy != NULL)
  17. {
  18. strncpy(temp,strtok(NULL, " "), MAX);
  19. count++;
  20. printf("TEMP IS: %s at count %d, sCopy is: %s", temp, count, sCopy);
  21. } // seg fault when this loop ends due to outrunning sCopy's size.
  22. printf("\ns = %s, sCopy = %s\n", s, sCopy);
  23. *argc = count;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment