하고자 하는 것
================================================================================================
지금 까지 짠 것
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct _poly
{
int x;
int y;
struct _poly *next;
}poly;
int main()
{
char buffer_1[100], buffer_2[100];
char *token, *saveptr;
int i;
poly *first, *second;
poly *current;
printf("first polynomial equation :");
scanf("%s", &buffer_1);
printf("second polynomial equation :");
scanf("%s", &buffer_2);
for(token = strtok(buffer_1, "x()+"), i=0 ; token != NULL; token = strtok(NULL, "x()+"),i++)
if (i%2==0)
{
if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
{
current = (poly *) malloc(sizeof(poly));
first=current;
}
else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
{
current->next=(poly *) malloc(sizeof(poly));
current=current->next;
}
current->x=atoi(token);
}
else
{
//새로운 노드의 y값에 대입
current->y=atoi(token);
}
for(token = strtok(buffer_2, "x()+"), i=0 ; token != NULL; token = strtok(NULL, "x()+"),i++)
if (i%2==0)
{
if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
{
current = (poly *) malloc(sizeof(poly));
second=current;
}
else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
{
current->next=(poly *) malloc(sizeof(poly));
current=current->next;
}
current->x=atoi(token);
}
else
{
//새로운 노드의 y값에 대입
current->y=atoi(token);
}
return 0;
}
==========================================================================================================
지금 이까지 열심히 해 봣는데요 머리가 터질것 같아요 ㅠㅠ
혼자 피피티 파일 보면서 독학 하는거라 어디 물어볼때가 없어요 ㅠㅠ
지금 저기 주석 달린 부분을 잘 모르겠어요.
if (i%2==0)
{
if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
{
current = (poly *) malloc(sizeof(poly));
first=current;
}
else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
{
current->next=(poly *) malloc(sizeof(poly));
current=current->next;
}
current->x=atoi(token);
}
else
{
//새로운 노드의 y값에 대입
current->y=atoi(token);
}
for(token = strtok(buffer_2, "x()+"), i=0 ; token != NULL; token = strtok(NULL, "x()+"),i++)
if (i%2==0)
{
if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
{
current = (poly *) malloc(sizeof(poly));
first=current;
}
else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
{
current->next=(poly *) malloc(sizeof(poly));
current=current->next;
}
current->x=atoi(token);
}
else
{
//새로운 노드의 y값에 대입
current->y=atoi(token);
}
아까 한 분께서 이렇게 하면 된다고 하셧는데, 이렇게 하면 두개의 식을 할 경우 덮어지므로,
하고자하는 더하기를 못하는게 아닌가요??
더하기를 하려면 어떻게 바꿔야 하죠?? ㅠㅠ
도와주세요 ㅠㅠ