0

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.

Konyac
  • 33
  • 9
  • 1
    Please define "them". – Yunnosch Oct 08 '19 at 17:12
  • 1
    Please describe what makes you think that the function does not work as it is. – Yunnosch Oct 08 '19 at 17:13
  • 1
    Please make an [mre] which allows us to reproduce the observations your describe. – Yunnosch Oct 08 '19 at 17:13
  • Why not use `qsort()` to sort the array? – Barmar Oct 08 '19 at 17:14
  • [dont cast malloc](https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc) – Barmar Oct 08 '19 at 17:15
  • You're not calling `calloc()` correctly. It takes 2 arguments, the number of elements and the element size. – Barmar Oct 08 '19 at 17:16
  • `fflush(stdin)` and `gets()` are both off the map. – Weather Vane Oct 08 '19 at 17:18
  • Please double check that the shown code compiles and demonstrates the described observations. I doubt that this compiles `int i,j:`. The immediatly following indentation is a nuisance, please do not undo helpful edits (in this case by Barmar). – Yunnosch Oct 08 '19 at 17:18
  • 1
  • 2
    Please delete the question. Compile the shown code with strict warnings. Fix all of them. Edit the shown code accordingly, undelete the question and then give feedback on the comments. Without that, the question lacks a [mre]. If the question is about why it does not compile and how to fix the first compiler error, then it does not lack an MRE but is unclear, because you do not describe the compiler error you are asking about. – Yunnosch Oct 08 '19 at 17:20
  • Yes, MSVC reports 12 compilation errors with 5 warnings. – Weather Vane Oct 08 '19 at 17:24
  • Do you want me to fix the code for you to something else that works better but you may have to learn it? – Kevin Ng Oct 13 '19 at 02:04

0 Answers0