Skip to content

Instantly share code, notes, and snippets.

@twxia
Created November 27, 2013 15:07
Show Gist options
  • Save twxia/7677194 to your computer and use it in GitHub Desktop.
Save twxia/7677194 to your computer and use it in GitHub Desktop.
PolyPointer readp()
{/*read in the polynomial */
PolyPointer node = NULL, c, headnode;
float coef=1;
int expon, i=0, count=0;
char str[100], tempc;
scanf("%s", str);
while (str[i] != '\0' ){
int sign = (int)coef;
expon = 0;
count = 1;
//printf("*c[%d]=%c* ",i,str[i]);
c = GetNode();
if(str[i] < '9' && str[i] > '0'){
sscanf(&str[i], "%f", &coef);
coef *= sign;
c->coef = coef;
c->expon = expon;
c->link = NULL;
for(int k = 10; k <= coef; k*=10) count++;
i += count;
}
switch(str[i]){
case 'x':
expon = 1;
if(str[++i] == '^'){
sscanf(&str[++i], "%d", &expon);
for(int k = 10; k <= expon; k*=10) count++;
i += (count-1);
}else{
i--;
}
c->expon = expon;
c->link = NULL;
break;
case '+':
coef = 1;
i++;
continue;
break;
case '-':
coef = -1;
i++;
continue;
break;
}
if(!node){
headnode = c;
node = c;
}else{
node->link = c;
node = c;
}
if(str[i]!='\0') i++;
}
return headnode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment