يا جماعة برنامج بسيط لكن لما اعطي تنفيذ بيطلع من البرنامج
ارجو المساعدة
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node *ptr;
typedef struct node2 *ptr2;
struct node
{
char part[20];
ptr next;
};
struct node2
{
char power[20];
char num[20];
ptr2 next;
};
typedef ptr list;
typedef ptr position;
typedef ptr2 list2;
typedef ptr2 position2;
int main()
{
FILE *in=fopen("data.txt","r");
char l[50];
fscanf(in,"%s",l);
char *tokptr,*tokptr2;
tokptr=strtok(l,"+");
list parts=(list) malloc(sizeof( struct node));
position temp =(position) malloc(sizeof(struct node));
temp=parts;
while (tokptr != NULL)
{
position name =(position) malloc(sizeof(struct node));
strcpy(name->part,tokptr);
printf(" \n %s",name->part);
temp->next=name;
temp=name;
tokptr=strtok(NULL,"+");
}
position2 temp1=(position2)malloc(sizeof(struct node2));
position temp2=(position)malloc(sizeof(struct node));
list2 p=(list2)malloc(sizeof(struct node2));
temp1=p;
temp2=parts;
while(temp2->next != NULL)
{
tokptr2=strtok(temp2->next->part,"x^");
position2 fun=(position2) malloc(sizeof(struct node2));
strcpy( fun->num,tokptr2);
printf(" \n %s " ,fun->num );
tokptr2=strtok(NULL,"^");
strcpy( fun->power,tokptr2);
printf(" %s" , fun->power);
temp1->next=fun;
temp1=fun;
temp2=temp2->next;
}
fclose(0);
printf(" \n %s " ,p->next->num);
return 0;
}