Q:

New Data is Replacing Older Data Instead Adding New Data in C

I am making simple C program. This program should be able to store data in memory (not using database). But when i tested it, it can not store more than 1 data. Every time i store new data, the old one get replaced. I hope these screenshot could help you understand what i mean.

As you can see, i input first set of data. It shows up with no problem.

Then, i added second set of data. Where is the first data ? The No 2 Data supposed to be after the No 1 data. But the first data get lost at all.
This is my input code :
//this is function for the input
void masukan() {
    n=n+1; //use n as index for the struct (mhsw)
    printf("\n");
    printf("Masukkan NIM : "); scanf("%s", mhsw[n].nim);
    printf("Masukkan Nama : "); scanf("%s", mhsw[n].nama);
    printf("Masukkan Golongan UKT : "); scanf("%d", &mhsw[n].golUKT);
    mhsw[n].nominalUKT = nominal(mhsw[n].golUKT)*100000;
    printf("");
}

//the nominal UKT = factorial of golUKT
int nominal(int n) {
    int hasil = 0;
    if (n == 1) return 15;
    else {
        hasil = ((n*n) + nominal(n-1));
        return hasil;
    }
}

This is my output code :
//this is for the output
    void tampil() {
    if (!kbhit()) {
    printf("\n");
    printf(" ===========================================================================\n");
    printf("                                 DATA MAHASISWA                              \n");
    printf("|====|================|====================|==============|=================|\n");
    printf("| No |       NIM      |        Nama        | Golongan UKT |   Nominal UKT   |\n");
    printf("|====|================|====================|==============|=================|\n");
        for(i=0; i<n; i++); //to display record
        {
            printf("%5d", i);
            printf("%17s", mhsw[i].nim);
            printf("%20s", mhsw[i].nama);
            printf("%15d", mhsw[i].golUKT);
            printf("%18d", mhsw[i].nominalUKT);
            printf("\n");
        }
    printf("|====|================|====================|==============|=================|\n");
    printf("\n \nPencet sembarang tombol untuk kembali ke Home");
    getch();
    } else {
        menu();
    }
}

This is the whole code :
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <windows.h>

//global variable
struct mahasiswa
{
    char nim[10];
    char nama[50];
    int golUKT;
    long int nominalUKT;
};
struct mahasiswa mhsw[50];
int i, n, nim;
bool ada = false;
char carinim[10];

//prototype
void login();
void menu();
void gotoxY(int, int);
void loading();
void masukan();
int nominal(int);
void tampil();
void cari();

//main function
void main() {
    login();
}

void login() {
    char user[10], pass[10];
    int x, y;
    printf("Masukkan Username : "); scanf("%s", user);
    printf("Masukkan Password : "); scanf("%s", pass);

    x = strcmp(user, "admin");
    y = strcmp(pass, "admin123");
    if (x == 0 && y == 0) {
        menu();
    }
    else {
        system("cls");
        printf("Gagal Login, Ulangi Proses\n");
        login();
    }
}

void menu()
{
    int pilih;

    system("cls");
    printf(" ____________________________________________________\n");
    printf("|                    Siukat Lite                     |\n");
    printf("|____________________________________________________|\n");
    printf("|_______________________Home_________________________|\n");
    printf("|    1. Pendaftaran Mahasiswa                        |\n");
    printf("|    2. Daftar Golongan UKT                          |\n");
    printf("|    3. Cari NIM                                     |\n");
    printf("|    4. Cetak Data Siukat                            |\n");
    printf("|    Ketik sembarang nomor untuk keluar              |\n");
    printf("|____________________________________________________|\n");
    printf("Masukkan Pilihan Nomor : ");
    scanf("%d",&pilih);

    switch(pilih)
    {
        case 1:
            //loading();
            printf("\nPendaftaran Mahasiswa");
            masukan();
            menu();
            break;
        case 2:
        case 3:
            printf("Cari NIM");
            cari();
            break;
        case 4:
            //loading();
            printf("\nData Siukat");
            tampil();
        default:
            menu();
    }
}

void gotoxy (int x,int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}

void loading() {
    int a;
    char x;

    gotoxy(1,12);
    for(a=0;a<=5;a++)
    {
        usleep(500000);
        printf("*",x);
    }
}

//for input record
void masukan() {
    printf("\n");
    printf("Masukkan NIM : "); scanf("%9s", mhsw[n].nim);
    printf("Masukkan Nama : "); scanf("%49s", mhsw[n].nama);
    printf("Masukkan Golongan UKT : "); scanf("%d", &mhsw[n].golUKT);
    mhsw[n].nominalUKT = nominal(mhsw[n].golUKT)*100000;
    printf("");
    n=n+1;
}

int nominal(int n) {
    int hasil = 0;
    if (n == 1) return 15;
    else {
        hasil = ((n*n) + nominal(n-1));
        return hasil;
    }
}

//for find NIM
void cari() {
    printf("\nMasukkan NIM :"); scanf("%s", carinim);
    printf("\n");
    if (!kbhit()) {
    for(i=0; i<n; i++) {
        if (strcmp(carinim, mhsw[i].nim) == 1) {
            ada = true;
        } else {
            ada = false;
        }
    }
        if(ada) {
            printf("NIM              : %s \n", mhsw[i].nim);

        } else {
            printf("Data Tidak Ditemukan");
        }
    } else {
        menu();
    }
}

//for showing the record
void tampil() {
    if (!kbhit()) {
    printf("\n");
    printf(" ===========================================================================\n");
    printf("                                 DATA MAHASISWA                              \n");
    printf("|====|================|====================|==============|=================|\n");
    printf("| No |       NIM      |        Nama        | Golongan UKT |   Nominal UKT   |\n");
    printf("|====|================|====================|==============|=================|\n");
        for(i=0; i<n; i++);
        {
            printf("%5d", i);
            printf("%17s", mhsw[i].nim);
            printf("%20s", mhsw[i].nama);
            printf("%15d", mhsw[i].golUKT);
            printf("%18d", mhsw[i].nominalUKT);
            printf("\n");
        }
    printf("|====|================|====================|==============|=================|\n");
    printf("\n \nPencet sembarang tombol untuk kembali ke Home");
    getch();
    } else {
        menu();
    }
}

Thanks for any help
UPDATE : i tried to put increment after the insertion and see the value of n. Still doesn't work. Here is some screenshot.

The value of n before insertion is still 0

The value of n after insertion, it incremented to 1. But the data doesn't get recorded at all.

A:

You have a ; after your for inside tampil().
for(i=0; i<n; i++);

It's causing your loop body to be empty so nothing is printed inside tampil().
To protect against such mistakes use a good compiler gcc and enable all warnings (for gcc it's -Wall -Wextra). Ex. gcc outputs this helpful warning message:
1.c: In function ‘tampil’:
1.c:167:9: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
  167 |         for(i=0; i<n; i++);
      |         ^~~
1.c:168:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
  168 |         {
      |         ^

