Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vertex strToVertex(char* str) {
- char *pch;
- int *parsed = calloc(1, sizeof(int));
- int *temp;
- int i = 0;
- pch = strtok (str," ,<->");
- parsed[i++] = atoi(pch);
- printf("First parsed int is %d\n", parsed[i-1]);
- pch = strtok (NULL, " ,<->");
- while (pch != NULL)
- {
- if (i > NELEMS(parsed)) {
- printf("%d is now larger than %d, resizing array.\n", i, NELEMS(parsed));
- temp = calloc(2 * NELEMS(parsed), sizeof(int));
- memcpy(temp, parsed, NELEMS(parsed) * sizeof(int));
- free(parsed);
- parsed = temp;
- }
- parsed[i++] = atoi(pch);
- printf("Next parsed int is %d\n", parsed[i-1]); //This prints out the element that I just added to the array
- pch = strtok (NULL, " ,<->");
- }
- printf("Finished parsing ints, amount is %d\n", i);
- printf("Parsed ints: \n");
- for (int j = 0; j <= NELEMS(parsed), j++;) {
- printf("Parsed: %d\n", parsed[j]); //Now there are no elements being printed; where the fuck did they go
- }
- //There was stuff here but it's irrelevant
- }
Add Comment
Please, Sign In to add comment