All pastes #996365 Raw Edit

Untitled

public text v1 · immutable
#996365 ·published 2008-04-24 21:52 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
#define _GNU_SOURCE

int main()
{
	int option, n, id, i;
	student *st = NULL;
	char name[64];
	
	
	while(1)
	{
		system("clear");
		displayMenu();
		scanf("%d", &option);
		
		if(option < 9 && option )
		{
			switch(option)
			{
				case 0:
					puts("");
					break;
					
				case 1:
					puts("Please insert the number of initial elements:");
					scanf("%d", &n);
					st = allocStructure(n);
					if(st != NULL)
					{
						puts("Memory succesfully allocated");
						getchar();
					}
					getchar();
					break;
					
				case 2:
					inputData(n, st);
					getchar();
					break;
					
				case 3:
					outputData(n, st);
					getchar();
					
					break;
				case 4:
					qsort(st, n, sizeof(student), cmpStudent);
					puts("Success!");
					getchar();
					getchar();
					break;
				case 5:
					puts("Type students' name:");
					scanf("%s", &name);
					searchStudent(st, name, n);
					getchar();
					getchar();
					break;
				case 6:
					addStudent(st, n);
					getchar();
					++n;
					break;
				case 7:
					puts("Enter student's id:");
					scanf("%d", &id);
					
					deleteStudent(st, id, n);
					getchar();
					getchar();
					--n;
					break;
				case 8:
					if ((file = fopen("student.dat", "w")) == NULL)
						fprintf(stderr, "Cannot open %s\n", "output_file");
					for(i=0;i<n;i++)
					{
						fprintf(file, "%s %d %f", st[i].name, st[i].year, st[i].mark);
					}
					break;
					
				case 9:
					if(!st)
					{
						free(st);
						st = NULL;
					}
					break;
				default: 
					puts("Invalid option:");
					getchar();
					getchar();
			}
		}
		
	}
}