rendered paste body#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define filename "bla.txt"
struct node
{
int AM;
char onoma[10],epnm[10];
struct node *next;
}*list_head,*neos,*s1;
struct node2
{
int AM;
int tilefwno1[10],tilefwno2[10];
struct node2 *next2;
}*list_head2,*neos2;
void add_node_to_list(int m);
void add_node_to_list2(int n);
void saveData(void);
void display_all_nodes();
main()
{
int i;
list_head=NULL;
list_head2=NULL;
for(i=1; i<=10; i++)
{
add_node_to_list(i);
}
for(i=1; i<=10; i++)
{
add_node_to_list2(i);
}
display_all_nodes();
saveData();
printf("1234567");
//system("pause");
getch();
}
/*Ç ðáñáêÜôù óõíÜñôçóç ðñïóèÝôåé Ýíáí êüìâï óôçí êïñõöÞ ôçò ëßóôáò */
void add_node_to_list(int m)
{
neos = (struct node *)malloc(sizeof(struct node));
neos->AM=m;
neos->next = list_head;
list_head=neos;
}
void add_node_to_list2(int n)
{
int i;
neos2 = (struct node2 *)malloc(sizeof(struct node2));
for(i=0; i<10; i++)
{
neos2->tilefwno1[i]=rand()%10;
neos2->tilefwno2[i]=rand()%10;
}
neos2->AM=n;
neos2->next2 = list_head2;
list_head2=neos2;
}
/*Ç ðáñáêÜôù óõíÜñôçóç åìöáíßæåé üëá ôá äåäïìÝíá ôçò ëßóôáò*/
void display_all_nodes()
{
struct node *p1;
struct node2 *p2;
p1=list_head;
p2=list_head2;
int i;
printf("Domi 1:\n");
while(p1!=NULL)
{
printf("Arithmos mitrwou = %d\n",p1->AM);
p1=p1->next;
}
printf("Domi 2:\n");
while(p2!=NULL)
{
printf("|-----------------------|\n");
printf("|");
printf("Arithmos mitrwou = %d |\n",p2->AM);
// printf("|");
// printf("---------------------|\n");
printf("|tilefwno 1 = ");
for(i=0; i<10; i++)
{
printf("%d",p2->tilefwno1[i]);
}
printf("|");
printf("\n");
printf("|tilefwno 2 = ");
for(i=0; i<10; i++)
{
printf("%d",p2->tilefwno2[i]);
}
printf("|");
printf("\n|-----------------------|\n");
printf("\n\n");
printf(" ----------***----------");
printf("\n\n");
p2=p2->next2;
}
}
void saveData(){
FILE *fp;
int i;
//struct node *p1;
fp=fopen(filename,"w");
if (fp == NULL) {
printf("To arxeio dn iparxei...\n");
exit(0);
}
while (s1!= NULL)
{
fprintf(fp, "%d ", s1->AM);
s1=s1->next;
}
fclose(fp);
}