With help of you guys, and a tutor, I have changed my code to the result of this so far. My tutor advised me that if I add in a section of code that helps process the binary tree, my alphabetical sorting will be easier.
I shall try to shrik the font size so the code isn't too long.
Code:
/* Student Roster by MATT NICOLA */
/* Final Project for Mike Fagan's Class */
/* INTRODUCTION:
The program was designed to input a number of students and sort them
into an alphabetical list. Ten grades will be assigned to each student
and the average will be found to complete a list of students and grades. */
/* REFERENCE:
Pg. 746 - Example of a Binary Tree
Pg. 460 - How to make a list */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Allotype(type) (type *)malloc(sizeof (type))
/* Set up a structure to work with the students and binary tree. */
typedef struct student { char Lastname[30];
char Firstname[20];
int Grade[10];
struct student *rootp;
struct student *leftp;
struct student *rightp;
struct student *tree_insert;
} MyStudent;
MyStudent *tree_insert(MyStudent *rootp, int new_pupil);
void listall(MyStudent *rootp);
/* The arrays will contain your students' first name, last name,
and grades. These must be alphabetical by finish. */
int
main(void) {
double student_limit,
student_count,
average;
int avgcnt;
student_limit = 0;
student_count = 0;
average = 0;
printf("Hello. Welcome to the student roster organizer.\n");
printf("This program is designed to input your students and\n");
printf("average their ten grades. Grades will be assigned\n");
printf("with their proper students.\n\n");
printf("Enter the number of students you wish to enter:");
scanf("%lf", &student_limit);
printf("\n\nNow for this part, enter the last name, enter the\n");
printf("first name, and then enter 10 seperate numbers that\n");
printf("determine the student's score.\n\n");
printf("REMEMBER: Enter one student at a time and continue until\n");
printf("the student limit has been reached.\n\n\n");
/* The while loop doesn't stop until all students are covered. */
while (student_count <= student_limit) {
scanf("%s", MyStudent Lastname);
printf(" ");
scanf("%s", MyStudent Firstname);
printf(" ");
scanf("%d", MyStudent Grade[0]);
printf(" ");
scanf("%d", MyStudent Grade[1]);
printf(" ");
scanf("%d", MyStudent Grade[2]);
printf(" ");
scanf("%d", MyStudent Grade[3]);
printf(" ");
scanf("%d", MyStudent Grade[4]);
printf(" ");
scanf("%d", MyStudent Grade[5]);
printf(" ");
scanf("%d", MyStudent Grade[6]);
printf(" ");
scanf("%d", MyStudent Grade[7]);
printf(" ");
scanf("%d", MyStudent Grade[8]);
printf(" ");
scanf("%d", MyStudent Grade[9]);
/* Each student will have 10 grades and they will present an average. */
for (avgcnt = 0; avgcnt < 10; ++avgcnt){
average = average + MyStudent Grade[avgcnt]; }
average = average / 10;
student_count = student_count + 1; }
/* The next passage processes the binary functions. */
MyStudent *no_pupil;
int keyinput;
int status;
no_pupil = NULL
for (status = MyStudent;
status == 1;
status = MyStudent) {
no_pupil = tree_insert(no_pupil, keyinput);
listall(no_pupil); }
if (status == 0)
{printf("Invalid! >>%c\n", getchar()); }
else
{listall(no_pupil); }
return(0); }
/* The binary tree will soon follow and it will place the entries into
alphabetical order. You might want to use an IF statement. */
MyStudent *
tree_insert (MyStudent *rootp,
int new_pupil)
{
/* If student has higher letter */
(if strcmp == -1)
{ rootp->leftp = tree_insert
(rootp->rightp, new_student); }
/* If student matches current student */
(else if strcmp == 0)
{/* Nothing happens */}
/* If student has lower letter */
(else if strcmp == 1)
{ rootp->rightp = tree_insert
(rootp->leftp, new_pupil); }
/* If student is NULL */
(else)
{rootp = Allotype(student);
rootp = new_pupil
rootp->leftp = NULL;
rootp->rightp = NULL; }
return (rootp);
}
Thank you for your concern Salem, but I am using the strcmp to compare the strings of students. Thus they will be sorted based upon a positive or negative answer from string compare.