online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <stdio.h> #include <string.h> #define SIZE 129 #define LEN 11 // student record structure typedef struct Student { char ID[LEN]; char name[LEN]; int math; int eng; int cs; } STUDENT; // check if the record is in the system // nedded by all the 4 functions int locate(STUDENT stu[SIZE], char sid[LEN], int count); // Followings are 4 functionalities void addRecord(STUDENT stu[SIZE], char sid[LEN], int count); void deleteRecord(STUDENT stu[SIZE], int loc, int count); void updateRecord(STUDENT stu[SIZE], int loc); void printRecord(STUDENT stu[SIZE], int loc); int main() { STUDENT stu[SIZE]; int op; char sid[LEN]; int i, n; int count = 0; // Total number of records in the system int loc; scanf("%d", &n); // how many actions to do for (i = 0; i < n; i++) { // read in ops and studentID in order to determine what to do scanf("%d%s", &op, sid); loc = locate(stu, sid, count); if (op == 1) // add { if (loc == -1) { addRecord(stu, sid, count); count++; } else { // read and discard input value scanf("%s%d%d%d", stu[count].name, &stu[count].math, &stu[count].eng, &stu[count].cs); printf("Students already exist\n"); } } else if (op == 2) // delete { if (loc != -1) { deleteRecord(stu, loc, count); count--; } else { printf("Students do not exist\n"); } } else if (op == 3) // update { if (loc != -1) { updateRecord(stu, loc); } else { // read and discard input value scanf("%d%d%d", &stu[count].math, &stu[count].eng, &stu[count].cs); printf("Students do not exist\n"); } } else if (op == 4) // print { if (loc != -1) { printRecord(stu, loc); } else { printf("Students do not exist\n"); } } } return 0; } int locate(STUDENT stu[SIZE], char sid[LEN], int count) { int loc = 0; while (loc < count) { if (strcmp(stu[loc].ID, sid) == 0) return loc; loc++; } return -1; // means no record } void addRecord(STUDENT stu[SIZE], char sid[LEN], int count) { strcpy(stu[count].ID, sid); scanf("%s", stu[count].name); scanf("%d%d%d", &stu[count].math, &stu[count].eng, &stu[count].cs); printf("Add success\n"); } void deleteRecord(STUDENT stu[SIZE], int loc, int count) { int i; for (i = loc; i < count - 1; i++) { stu[i] = stu[i + 1]; } printf("Delete success\n"); } void updateRecord(STUDENT stu[SIZE], int loc) { scanf("%d%d%d", &stu[loc].math, &stu[loc].eng, &stu[loc].cs); printf("Update success\n"); } void printRecord(STUDENT stu[SIZE], int loc) { printf("Student ID:%s\nName:%s\n", stu[loc].ID, stu[loc].name); printf("Average Score:%.1f\n", (stu[loc].math + stu[loc].eng + stu[loc].cs) / 3.0); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue