I really need help for this, like i want to print out them and what do i need to adding to this function to work.
#include <stdio.h>
#include <stdlib.h>
#define nameSizeMax 31
#define listSizeMax 100
char studentList[listSizeMax][nameSizeMax];
int listSize;
void addStudent() {
if(listSize == listSizeMax) {
printf("List is full!\n\n");
} else {
printf("Enter name of the student: ");
fflush(stdin);
char name[nameSizeMax];
gets(name);
trim(name);
strupr(name);
strcpy(studentList[listSize], name);
listSize++;
printf("The new student have been added!\n\n");
}
}
int searchStd(char list[][nameSizeMax], char item[], int size) {
int i;
for(i=0;i<size; i++);
if (strcmp(list[i], item) == 0) return 1;
return -1;
}
void removeStudent() {
int i
if (listSize == 0) {
printf("List is empty!\n\n");
} else {
printf ("Enter name of the removed student: ");
fflush(stdin);
char name[nameSizeMax];
gets(name);
trim(name);
strupr(name);
int pos = searchStd(studentList, name, listSize);
}
if(pos == -1) {
printf("This student does not exist!\n\n");
} else {
for (i=pos; i<listSize-1; i++);
strcpy(studentList[i], studentList[i+1]);
printf("This student has been removed from the list: \n\n");
listSize--;
}
}
void fintStudent() {
int i;
printf("Enter the name of student you want to search: ");
fflush(stdin);
char name[nameSizeMax];
gets(name);
trim(name);
strupr(name);
int pos = searchStd(studentList, name, listSize);
if(pos == -1) {
printf("This student does not exist:\n\n");
} else {
printf("\n This is the student list in the order you entered: \n");
for(i=0; i<listSize; i++) printf("%d - %s\n", i, studentList[i]);
printf ("This student's postition in the list is: %d\n\n", pos);
}
}
void printStudentAsc(char list[][nameSizeMax], int size) {
int i,j:
if (listSize == 0) {
printf("List is empty!\n\n");
} else {
char **listP = (char **) calloc(sizeof(char *));
for (i=o; i<size; i++) listP[i] = list[i];
for (i=0; i<size-1; i++)
for(j=i+1; j<size; j++) {
char *ln1,*ln2;
ln1= lastname(listP[i]);
ln2= lastname(listP[j]);
if (strcmp(ln1, ln2) == 1) {
char *tmp = listP[i];
listP[i] =listP[j];
listP[j] = tmp;
}
}
}
for (i = 0; i < (*pn); i++)
{
nameStr(list[i]);
printf("Name[%d] : %s \n", i, list[i]);
}
}
int menu(){
printf("Menu:\n");
printf("1- Add a student\n");
printf("2- Remove a student\n");
printf("3- Search a student\n");
printf("4- Print out the student list in ascending order\n");
int userChoice;
do{
printf("Insert ur operation: "); scanf("%d", &userChoice);
}
}
Edited :'( i really struggle about the printAsc like i dont know what to do next . Its really messed me up here. Only the printStudentAsc.
the Menu interface that im not finish yet but i can hanlde this.