Im having trouble with this code
It gives me backCode:int getpackagename(char *package, char **dest) { int x = 0; int y = 0; while(package[x] != '\0') { if(package[x] == '-') { ++x; if( isdigit(package[x]) != 0 ) { ++x; *dest = malloc( strlen(package) - x + 1 ); while(package[x] != '\0') { printf("x = %i\ty = %i\n", x, y); *dest[y] = package[x]; ++y; ++x; } *dest[y] = '\0'; return 0; } } ++x; } return 1; } int main(int argc, char *argv[]) { char package[] = "test-1.0.0"; char *test = NULL; getpackagename(package, &test); printf("%s\n", test); free(test); return 0; }
And then it crashes. I have no idea why.x = 6 y = 0
x = 7 y = 1
Any ideas?