Hi!
I have problem with the "ReadList" and "WriteList" function.
Thnx in advanceCode:# include <stdio.h> # include <stdlib.h> # include <ctype.h> # include <conio.h> # define FALSE 0 typedef struct { int Value; struct List *link; } List; // other functions void clrscr (void); void Menu (int *Choose); // functions for the list List *AddElement (List *start, int Data); void ReadList (List *start, char File01[]); void WriteList (List *start, char File01[]); void PrintList (List *start); int main() { int Choose, Data; List *start = NULL; start = ReadList(start, "data.txt"); do { Menu(&Choose); switch (Choose) { case 1: printf("\nEnter number: "); scanf("%d", &Data); start = AddElement(start, Data); break; case 2: if (start != NULL) { PrintList(start); } else { printf("\nList is empty."); } getch(); break; case 3: break; default: printf("\nWrong selection. Try again."); getch(); break; } } while (Choose != 3); WriteList (start, "data.txt"); return 0; } void Menu (int *Choose) { unsigned char Char; do { clrscr(); printf("List"); printf("\n\n1 - Add element into sorted list"); printf("\n2 - Print elements on the screen"); printf("\n3 - Exit"); printf("\n\nChoose: "); Char = getchar(); if ((isdigit (Char) == FALSE) && (Char != '\n')) { printf ("\nYou must enter number."); getch(); } } while (isdigit (Char) == FALSE); *Choose = (int) Char - '0'; } void clrscr() { system("cls"); } List *AddElement (List *start, int Data) { List *pom, *New; New = (List *) malloc(sizeof(List)); New->Value = Data; if ( (start == NULL) || (New->Value <= start->Value) ) { (List *)New->link = start; start = New; } else { pom = start; while ( (pom->link != NULL) && (New->Value > ((List *)pom->link)->Value) ) { pom = (List *)pom->link; } New->link = pom->link; (List *)pom->link = New; } return start; } void PrintList (List *start) { while (start != NULL) { printf("%d\t", start->Value); start = (List *)start->link; } }.



LinkBack URL
About LinkBacks
. 


