typedef struct _poly_t { char *exp; char *numb; }poly_t; static poly_t* allocatePoly(const char *data){ poly_t *ptr = (poly_t*)malloc(sizeof(poly_t)); ptr->exp = (char *)malloc(120*sizeof(char)); ptr->numb = (char *)malloc(120*sizeof(char)); memset(ptr->exp, '\0', 128); memset(ptr->numb, '\0', 128); return ptr; } poly_t *new_poly_from_string(const char* theString){ poly_t *ptr = allocatePoly(theString); char *writablestring; char *token = NULL; int counter = 0; char *tempchar; writablestring = (char *)malloc(strlen(theString)); strcpy(writablestring, theString); token = strtok(writablestring, " "); while(token != NULL){ if( (tempchar = strpbrk(token, "^")) != NULL ){ strncpy(ptr->numb,tempchar+1, strlen(tempchar+1)); } printf("[%s]\n", token); token = strtok(NULL, " "); counter++; } return ptr; } void free_poly(poly_t* thePoly){ free(thePoly); } char* poly_to_string(poly_t* thePoly){ //Behövs ej göras. return NULL; } poly_t* add(poly_t* a, poly_t* b){ return a; } poly_t* mul(poly_t* a, poly_t* b){ return NULL; } void print_poly(poly_t* toPrint){ printf("%s: %s", toPrint->exp, toPrint->numb); // HUR SKRIVER JAG UT toPrint->numb & toPrint->exp? } void main(int argc, char **argv) { poly_t *ptr = new_poly_from_string("12^3 456"); print_poly(ptr); }