Guest User

Untitled

a guest
Dec 15th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. Vertex strToVertex(char* str) {
  2. char *pch;
  3. int *parsed = calloc(1, sizeof(int));
  4. int *temp;
  5. int i = 0;
  6. pch = strtok (str," ,<->");
  7. parsed[i++] = atoi(pch);
  8. printf("First parsed int is %d\n", parsed[i-1]);
  9. pch = strtok (NULL, " ,<->");
  10. while (pch != NULL)
  11. {
  12. if (i > NELEMS(parsed)) {
  13. printf("%d is now larger than %d, resizing array.\n", i, NELEMS(parsed));
  14. temp = calloc(2 * NELEMS(parsed), sizeof(int));
  15. memcpy(temp, parsed, NELEMS(parsed) * sizeof(int));
  16. free(parsed);
  17. parsed = temp;
  18. }
  19. parsed[i++] = atoi(pch);
  20. printf("Next parsed int is %d\n", parsed[i-1]); //This prints out the element that I just added to the array
  21. pch = strtok (NULL, " ,<->");
  22. }
  23. printf("Finished parsing ints, amount is %d\n", i);
  24. printf("Parsed ints: \n");
  25. for (int j = 0; j <= NELEMS(parsed), j++;) {
  26. printf("Parsed: %d\n", parsed[j]); //Now there are no elements being printed; where the fuck did they go
  27. }
  28. //There was stuff here but it's irrelevant
  29. }
Add Comment
Please, Sign In to add comment