online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <stdio.h> #include <stdlib.h> #include <string.h> struct studInfo { int studNr; char studName[12]; int grade; }; struct node{ struct studInfo info; struct node *link; }; typedef struct node *NODEPTR; NODEPTR getnode(void); void fileIntoArray(struct studInfo allStudent[],int *num); void sortByNum(struct studInfo allstudent[],NODEPTR *, int num); void list(NODEPTR); int main() { struct studInfo allStudent[150]; NODEPTR headNum, headName; int choice; int num; fileIntoArray(allStudent, &num); sortByNum(allStudent, &headNum, num); list(headNum); return 0; } void fileIntoArray(struct studInfo allStudent[], int *num) { FILE *ptr = fopen("student.txt","r"); int i = 0; while(!feof(ptr)) { fscanf(ptr,"%d%s%d",&allStudent[i].studNr,allStudent[i].studName,&allStudent[i].grade); i++; } *num = i; fclose(ptr); } void sortByNum(struct studInfo allStudent[], NODEPTR *headNum, int num) { NODEPTR head, p, save, prev; head = NULL; for(int i = 0; i<=num; ++i) { p = getnode(); p->info=allStudent[i]; if(head=NULL){ head = p; p -> link = NULL; } else{ if(p->info.studNr < head->info.studNr){ p->link = head; head = p; } else{ save = head; while((save->info.studNr < p->info.studNr)&&(save!=NULL)){ prev = save; save = save->link; if(save==NULL){ prev->link = p; p->link = NULL; } else{ p->link = prev->link; prev->link = p; } } } } } *headNum = head; } void list(NODEPTR headNum) { NODEPTR p = headNum; int line = 0; while(p->link!=NULL) { line++; if(line>25){ printf("Tab a button\n"); getchar(); line=1; } printf("%d %d %s %d\n",line,p->info.studNr,p->info.studName,p->info.grade); p = p->link; } } NODEPTR getnode() { NODEPTR q; q = (NODEPTR) malloc(sizeof(struct node)); return(q); }
26422 ENGIN 75 27798 EMRAH 85 32351 ALBAYRAK 66 34259 DURAN 75 34970 EREN 45 35175 UGUR 97 36124 KAMURAN 65 36126 AHME 87 36132 ERHAN 54 36136 OZKARA 45 16322 REMZI 98 36980 AKCAY 100 37084 TOYGUN 60 37096 OSMAN 94 37941 BASHER 77 61334 MUHSIN 77 61435 MUHAMMED 84 21437 EREN 94 61438 GURKAN 83 61439 MEHMET 77 31440 KORAY 59 62133 KEMAHLIOGLU 52 41252 GOKHAN 75 42268 BULENT 79 52355 NECMETTIN 88 42358 CAHIT 53 42406 ODABASIOGLU 49 44264 KARANFIL 88 67807 SIBEL 44 47942 ALI 87 51165 HAKAN 95 51270 VOLKAN 74 72159 HASAN 50 52161 RAHMIYE 53 53261 SEDA 85 53266 HASAN 68 54261 FATIH 100 56134 KUBILAY 67 86137 OZTURK 92 56141 GOKHAN 55 57293 CAVIT 39 97293 ARIKAN 55 57294 FATMA 100 87294 SENIHA 48 57825 KARACA 57 60266 HAKKI 84 41221 ONUR 66 61222 SERAP 39 61223 AYHAN 73 61225 HAKAN 55 11229 AHMET 45 64242 AHMAD 59 54272 BURCAK 52 24278 YAGMUR 46 64422 ERGUN 59 64423 ALPEREN 35 35324 RAZIYE 100 66135 FATMACAN 71 67434 AHMEDHAN 70 37895 ZEKIYE 49 47944 FAIZAN 94 68219 SYED_WASIM 94 38222 KASHIF_HUSN 49 61328 EMRAH 50 61329 BURAK 49 91331 NURGUL 37 62419 GUNES 93 62963 CERAR 48 62967 BULENT 83 83420 MUGE 100 63421 NEDIM 65 63582 ADEMSAY 67 94136 BURAKSUZ 52 64230 ZELIHAN 85 69202 TOLGAC 100 69206 CUNEYT_ASIM 65 45718 MOHAMMAD 45 6126 MEHMET 23 46415 OYA 47 46440 SEFEROL 87 46971 SENAY_SAHIN 56 77080 METE 89 47293 GURKAN 34 47790 ADEMAL 74

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