Advertisement
Guest User

Untitled

a guest
May 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.70 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. //#define clear() printf("\033[H\033[J")
  5. #define ANSI_COLOR_RED "\x1b[31m"
  6. #define ANSI_COLOR_GREEN "\x1b[32m"
  7. #define ANSI_COLOR_YELLOW "\x1b[33m"
  8. #define ANSI_COLOR_BLUE "\x1b[34m"
  9. #define ANSI_COLOR_MAGENTA "\x1b[35m"
  10. #define ANSI_COLOR_CYAN "\x1b[36m"
  11. #define ANSI_COLOR_RESET "\x1b[0m"
  12. struct node
  13. {
  14. char prenume[20],nume[20],facultatea[20],specializarea[20];
  15. int note[10],media;
  16. struct node *adr_urm;
  17. };
  18. struct node *primul=NULL;
  19. struct node *ultimul=NULL;
  20. struct node* createNode()
  21. {
  22. struct node *temp;
  23. temp=(struct node*)malloc(sizeof(struct node));
  24. return temp;
  25. };
  26. int cautare();
  27. void inserare_fata();
  28. void inserare_spate();
  29. void printare();
  30. void modifica_student();
  31. void adauga_nota_student();
  32. int afisare_medie();
  33. void sterge_student();
  34. void inserare_in_fisier();
  35. void inserare_alfabetic_in_fisier();
  36. void afisare_alfabetica();
  37. void afisare_nr_studenti();
  38. void get_student();
  39. void inserare_note_multiple_sfarsit();
  40. void get_sudent_alfabetic();
  41. int main()
  42. {
  43. char nume[20],prenume[20],specializare[20],facultate[20];
  44. int nota,index;
  45. int choice=0;
  46. do
  47. {
  48. printf(ANSI_COLOR_MAGENTA "\n\tMENIU STUDENTI");//MENIUL PRINCIPAL
  49. printf("\n\t------------------------------" ANSI_COLOR_RESET);
  50. printf(ANSI_COLOR_RED "\n\t 1. ADAUGA STUDENT LA INCEPUT" ANSI_COLOR_RESET);
  51. printf(ANSI_COLOR_RED "\n\t 2. MODIFICA STUDENT" ANSI_COLOR_RESET);
  52. printf(ANSI_COLOR_RED "\n\t 3. AFISEAZA LISTA DE STUDENTI" ANSI_COLOR_RESET);
  53. printf(ANSI_COLOR_RED "\n\t 4. ADAUGA STUDENT LA SFARSIT" ANSI_COLOR_RESET);
  54. printf(ANSI_COLOR_YELLOW "\n\t 5. MODIFICAREA NOTELOR UNUI STUDENT" ANSI_COLOR_RESET);
  55. printf(ANSI_COLOR_YELLOW "\n\t 6. AFISAREA MEDIEI NOTELOR UNUI STUDENT" ANSI_COLOR_RESET);
  56. printf(ANSI_COLOR_YELLOW "\n\t 7. STERGEREA UNUI STUDENT" ANSI_COLOR_RESET);
  57. printf(ANSI_COLOR_BLUE "\n\t 8. SALVATI: INSERATI TOTUL INTR-UN FISIER !!!" ANSI_COLOR_RESET);
  58. printf(ANSI_COLOR_BLUE "\n\t 9. SALVATI: INSERATI TOTUL INTR-UN FISIER ALFABETIC !!!" ANSI_COLOR_RESET);
  59. printf(ANSI_COLOR_BLUE "\n\t 10. AFISARE ALFABETICA !!!" ANSI_COLOR_RESET);
  60. printf(ANSI_COLOR_BLUE "\n\t 11. AFISAREA NUMARUL STUDENTIILOR INSCRISI IN LISTA !!!" ANSI_COLOR_RESET);
  61. printf(ANSI_COLOR_GREEN "\n\t 12. IMPORTARE STUDENTI SALVATI DIN FISIER !" ANSI_COLOR_RESET);
  62. printf(ANSI_COLOR_GREEN "\n\t 13. IMPORTARE STUDENTI SALVATI ALFABETIC DIN FISIER!" ANSI_COLOR_RESET);
  63. printf(ANSI_COLOR_CYAN "\n\t 14. EXIT !!!" ANSI_COLOR_RESET);
  64. printf(ANSI_COLOR_RED "\n\n INSERATI NUMARUL DORIT: " ANSI_COLOR_RESET);
  65. printf(ANSI_COLOR_RED);
  66. scanf("%d",&choice);
  67. // clear();
  68. printf("\n");
  69. switch(choice)
  70. {
  71. case 1:
  72. printf("\n INTRODUCE-TI STUDENTII IN LISTA \n");
  73. printf("PRENUME:\n");
  74. scanf("%s",prenume);
  75. printf("NUME: \n");
  76. scanf("%s",nume);
  77. printf("FACULTATE:\n");
  78. scanf("%s",facultate);
  79. printf("SPECIALIZARE:\n");
  80. scanf("%s",specializare);
  81. printf("NOTA:\n");
  82. scanf("%d",&nota);
  83. printf("NR NOTA:\n");
  84. scanf("%d",&index);
  85. if(index<11&&nota<11)
  86. {
  87. inserare_fata(prenume,nume,facultate,specializare,nota,index);
  88. printf("\n\n\n\n\n\n\n\n\n\n\n");
  89. }
  90. else
  91. {
  92. printf("\n\n\nINDEXUL NOTEI SAU NOTA ESTE PREA MARE\n");
  93. }
  94. break;
  95. case 2:
  96. printf("\nATI SLECTAT OPTIUNEA DE MODIFICARE A UNUI STUDENT \n");
  97. printf("PRENUME:\n");
  98. scanf("%s",prenume);
  99. printf("NUME: \n");
  100. scanf("%s",nume);
  101. modifica_student(nume,prenume);
  102. break;
  103. case 3:
  104. printf("\nATI SLECTAT OPTIUNEA DE AFISARE A STUDENTIILOR \n");
  105. printare();
  106. break;
  107. case 4:
  108. printf("\n INTRODUCE-TI STUDENTII IN LISTA \n");
  109. printf("PRENUME:\n");
  110. scanf("%s",prenume);
  111. printf("NUME: \n");
  112. scanf("%s",nume);
  113. printf("FACULTATE:\n");
  114. scanf("%s",facultate);
  115. printf("SPECIALIZARE:\n");
  116. scanf("%s",specializare);
  117. printf("NOTA:\n");
  118. scanf("%d",&nota);
  119. printf("NR NOTA:\n");
  120. scanf("%d",&index);
  121. if(index<11&&nota<11)
  122. {
  123. inserare_spate(prenume,nume,facultate,specializare,nota,index);
  124. printf("\n\n\n\n\n\n\n\n\n\n\n");
  125. }
  126. else
  127. {
  128. printf("\n\n\nINDEXUL NOTEI SAU NOTA ESTE PREA MARE\n");
  129. }
  130. break;
  131. case 5:
  132. printf("\nATI SLECTAT OPTIUNEA PT MODIFICAREA NOTEI UNUI STUDENT \n");
  133. printf("PRENUME:\n");
  134. scanf("%s",prenume);
  135. printf("NUME: \n");
  136. scanf("%s",nume);
  137. adauga_nota_student(nume,prenume);
  138. break;
  139. case 6:
  140. printf("PRENUME:\n");
  141. scanf("%s",prenume);
  142. printf("NUME: \n");
  143. scanf("%s",nume);
  144. afisare_medie(nume,prenume);
  145. break;
  146. case 7:
  147. sterge_student();
  148. break;
  149. case 8:
  150. inserare_in_fisier();
  151. printf("\n SALVARE EFECTUATA CU SUCCES \n");
  152. break;
  153. case 9:
  154. inserare_alfabetic_in_fisier();
  155. printf("\n INSERARE IN FISIER EFECTUATA CU SUCCES\n");
  156. break;
  157. case 10:
  158. afisare_alfabetica();
  159. printf("\n STUDENTII AU FOST AFISATI IN ORDINE ALFABETICA\n");
  160. break;
  161. case 11:
  162. afisare_nr_studenti();
  163. break;
  164. case 12:
  165. get_student();
  166. printf("\n INCARCARE EFECTUATA CU SUCCES ! \n");
  167. break;
  168. case 13:
  169. get_sudent_alfabetic();
  170. printf("\n INCARCARE ALFABETICA EFECTUATA CU SUCCES ! \n");
  171. break;
  172. case 14:
  173. printf("\nATI SELECTAT CEA DE-A PATRA ACTIUNE, \n MULTUMIM PENTRU UTILIZARE \n");
  174. exit(0);
  175. break;
  176. default:
  177. printf("\nALEGERE INVALIDA...Te rog sa mai incerci !!! \n");
  178. }
  179. }while(choice!=14);
  180. return 0;
  181. }
  182. int cautare(char *pren,char *num)//FUNCTIE DE CAUTARE
  183. {
  184. struct node *traverse;
  185. traverse=createNode();
  186. traverse=primul;
  187. int i=0;
  188. while(traverse!=NULL)
  189. {
  190. i++;
  191. if((strcmp(traverse->nume,num)&&strcmp(traverse->prenume,pren))==0)
  192. {
  193. return i;
  194. }
  195. traverse=traverse->adr_urm;
  196. }
  197. return 0;
  198. }
  199. void inserare_fata(char pren[20],char num[20],char fac[20],char spec[20],int not,int index)//FUNCTIE PENTRU INSERAREA UNUI STUDENT IN FATA LISTEI
  200. {
  201. struct node *temp;
  202. temp=createNode();
  203. strcpy(temp->nume,num);
  204. strcpy(temp->prenume,pren);
  205. strcpy(temp->facultatea,fac);
  206. strcpy(temp->specializarea,spec);
  207. if(not<11)
  208. {
  209. temp->note[index]=not;
  210. }
  211. if(primul==NULL)
  212. {
  213. primul=temp;
  214. }
  215. else
  216. {
  217. temp->adr_urm=primul;
  218. primul=temp;
  219. }
  220. }
  221. void inserare_spate(char pren[20],char num[20],char fac[20],char spec[20],int not,int index)//FUNCTIE PENTRU INSERAREA UNUI STUDENT IN SPATELE LISTEI
  222. {
  223. struct node *temp;
  224. struct node *traverse;
  225. traverse=primul;
  226. temp=createNode();
  227. strcpy(temp->nume,num);
  228. strcpy(temp->prenume,pren);
  229. strcpy(temp->facultatea,fac);
  230. strcpy(temp->specializarea,spec);
  231. if(not<11)
  232. {
  233. temp->note[index]=not;
  234. }
  235. if(primul==NULL)
  236. {
  237. primul=temp;
  238. }
  239. else
  240. {
  241. while(traverse->adr_urm!=NULL)
  242. {
  243. traverse=traverse->adr_urm;
  244. }
  245. traverse->adr_urm=temp;
  246. }
  247. }
  248. void printare()//FUNCTIE DE AFISAREA
  249. {
  250. struct node *traverse;
  251. traverse=primul;
  252. int i;
  253. while(traverse!=NULL)
  254. {
  255. printf("PRENUME: %s \n ",traverse->prenume);
  256. printf("NUME: %s\n",traverse->nume);
  257. printf("FACULTATE: %s \n",traverse->facultatea);
  258. printf("SPECIALIZARE: %s\n",traverse->specializarea);
  259. printf("NOTE: \n");
  260. for(i=0;i<10;i++)
  261. {
  262. printf("%d ",traverse->note[i]);
  263. }
  264. printf("\n");
  265. afisare_medie(traverse->nume,traverse->prenume);
  266. traverse=traverse->adr_urm;
  267. printf("\n");
  268. printf("\n");
  269. }
  270. }
  271. void modifica_student(char num[20],char prenum[20])//FUNCTIE PENTRU MODIFICAREA DATELOR UNUI STUDENT
  272. {
  273. char facultate[20],specializare[20];
  274. int nota,index,n=0;
  275. struct node *traverse;
  276. traverse=primul;
  277. while(traverse!=NULL&&n!=-1)
  278. {
  279. if((strcmp(traverse->nume,num)&&strcmp(traverse->prenume,prenum))==0)
  280. {
  281. printf("STUDENT GASIT !!! \n \n \n");
  282. printf("FACULTATE:\n");
  283. scanf("%s",facultate);
  284. strcpy(traverse->facultatea,facultate);
  285. printf("SPECIALIZARE:\n");
  286. scanf("%s",specializare);
  287. strcpy(traverse->specializarea,specializare);
  288. printf("NR NOTA:\n");
  289. scanf("%d",&index);
  290. printf("NOTA:\n");
  291. scanf("%d",&nota);
  292. if(nota<11)
  293. {
  294. traverse->note[index]=nota;
  295. }
  296. else
  297. {
  298. printf("\nEROARE, NOTA SAU INDEXUL NOTEI SUNT PREA MARE\n");
  299. }
  300. printf("PENTRU REVENIREA LA MENIUL PRINCIPAL INSERATI -1 \n\n");
  301. scanf("%d",&n);
  302. }
  303. traverse=traverse->adr_urm;
  304. }
  305. }
  306. void adauga_nota_student(char num[20],char prenum[20])//FUNCTIE PT ADAUGAREA DE NOTE UNUI STUDENT
  307. {
  308. int nota,index,n=0;
  309. struct node *traverse;
  310. traverse=primul;
  311. while(traverse!=NULL&&n!=-1)
  312. {
  313. if((strcmp(traverse->nume,num)&&strcmp(traverse->prenume,prenum))==0)
  314. {
  315. printf("STUDENT GASIT, PUTETI MODIFICA NOTA !!! \n \n \n");
  316. printf("NR NOTA:\n");
  317. scanf("%d",&index);
  318. printf("NOTA:\n");
  319. scanf("%d",&nota);
  320. if(nota<11&&index<11)
  321. {
  322. traverse->note[index]=nota;
  323. }
  324. else
  325. {
  326. printf("\nEROARE, NOTA SAU INDEXUL NOTEI SUNT PREA MARI \n");
  327. }
  328. printf("PENTRU REVENIREA LA MENIUL PRINCIPAL INSERATI -1 \n\n");
  329. scanf("%d",&n);
  330. }
  331. traverse=traverse->adr_urm;
  332. }
  333. }
  334. int afisare_medie(char num[20],char prenum[20])//FUNCTIE PENTRU AFISAREA MEDIE NOTELOR
  335. {
  336. struct node *traverse;
  337. struct node *temp;
  338. temp=createNode();
  339. traverse=primul;
  340. int sum=0,i,nr=0;
  341. while(traverse!=NULL)
  342. {
  343. if((strcmp(traverse->nume,num)&&strcmp(traverse->prenume,prenum))==0)
  344. {
  345. for(i=0;i<10;i++)
  346. {
  347. if(traverse->note[i]!=0)
  348. {
  349. sum=sum+traverse->note[i];
  350. nr++;
  351. }
  352. }
  353. }
  354. traverse=traverse->adr_urm;
  355. }
  356. temp->media=sum/nr;
  357. printf("MEDIA NOTELOR STUDENTULUI ESTE: %d \n",temp->media);
  358. return temp->media;
  359. }
  360. void sterge_student()//FUNCTIE DE STERGERE A UNUI STUDENT
  361. {
  362. char nume[20],prenume[20];
  363. printf("PRENUME:\n");
  364. scanf("%s",prenume);
  365. printf("NUME: \n");
  366. scanf("%s",nume);
  367. int i,n=cautare(prenume,nume);
  368. struct node *temp=primul,*prev;
  369. prev=createNode();
  370. if(n==0)
  371. {
  372. printf("\n EROARE, STERGEREA NU S-A PUTUT EFECTUA !!! \n");
  373. }
  374. if(n==1)
  375. {
  376. primul=temp->adr_urm;
  377. free(temp);
  378. printf("\n STERGEREA S-A EFECTUAT CU SUCCES ! \n");
  379. }
  380. else
  381. {
  382. for(i=1;i<=n;i++)
  383. {
  384. if(i==n)
  385. {
  386. if(temp->adr_urm==NULL)
  387. {
  388. prev->adr_urm=NULL;
  389. ultimul=prev;
  390. free(temp);
  391. printf("\n STERGEREA S-A EFECTUAT CU SUCCES ! \n");
  392. }
  393. else
  394. {
  395. prev->adr_urm=temp->adr_urm;
  396. free(temp);
  397. printf("\n STERGEREA S-A EFECTUAT CU SUCCES! \n");
  398. }
  399. }
  400. prev=temp;
  401. temp=temp->adr_urm;
  402. }
  403. }
  404. }
  405. void inserare_in_fisier()//FUNCTIE PENTRU INSERAERA INTR-UN FISIER
  406. {
  407. FILE *fp,*fs;
  408. fp=fopen("studenti.txt","w");
  409. fs=fopen("studenti_backup.txt","w");
  410. int i,med;
  411. struct node *temp;
  412. temp=primul;
  413. while(temp!=NULL)
  414. {
  415. fprintf(fp,"Prenume: %s",temp->prenume);
  416. fprintf(fp," Nume: %s",temp->nume);
  417. fprintf(fp," Facultate: %s",temp->facultatea);
  418. fprintf(fp," Specializare: %s",temp->specializarea);
  419. fprintf(fp," Note: ");
  420. fprintf(fs,"%s ",temp->prenume);
  421. fprintf(fs,"%s ",temp->nume);
  422. fprintf(fs,"%s ",temp->facultatea);
  423. fprintf(fs,"%s ",temp->specializarea);
  424. for(i=0;i<10;i++)
  425. {
  426. fprintf(fp," %d",temp->note[i]);
  427. fprintf(fs," %d",temp->note[i]);
  428. }
  429. fprintf(fp," ");
  430. med=afisare_medie(temp->nume,temp->prenume);
  431. fprintf(fp,"Media studentului: %d ",med);
  432. fprintf(fp,"\n\n\n");
  433. fprintf(fs," %d",med);
  434. fprintf(fs,"\n");
  435. temp=temp->adr_urm;
  436. }
  437. fclose(fp);
  438. fclose(fs);
  439. }
  440. void inserare_alfabetic_in_fisier()//FUNCTIE PENTRU INSERAREA IN ORDINE ALFABETICA INTR-UN FISIER
  441. {
  442. char temp_var[20];
  443. int temp_var2,med;
  444. int i,j,z,count=0;
  445. struct node *temp;
  446. temp=primul;
  447. struct studenti
  448. {
  449. char prenume[20],nume[20],facultatea[20],specializarea[20];
  450. int note[10],media;
  451. };
  452. while (temp!=NULL)
  453. {
  454. count++;
  455. temp=temp->adr_urm;
  456. }
  457. struct studenti stud[count];
  458. FILE *fs,*fp;
  459. fs=fopen("studenti_alfabetic.txt","w");
  460. fp=fopen("studenti_alfabetic_backup.txt","w");
  461. temp=primul;
  462. for(i=0;i<count;i++)
  463. {
  464. if(temp!=NULL)
  465. {
  466. strcpy(stud[i].prenume,temp->prenume);
  467. strcpy(stud[i].nume,temp->nume);
  468. strcpy(stud[i].facultatea,temp->facultatea);
  469. strcpy(stud[i].specializarea,temp->specializarea);
  470. for(j=0;j<10;j++)
  471. {
  472. stud[i].note[j]=temp->note[j];
  473. }
  474. }
  475. temp=temp->adr_urm;
  476. }
  477. for(i=0;i<count-1;i++)
  478. {
  479. for(j=0;j<count-i-1;j++)
  480. {
  481. if(strcmp(stud[j].nume,stud[j+1].nume)>0)
  482. {
  483. strcpy(temp_var,stud[j].nume);
  484. strcpy(stud[j].nume,stud[j+1].nume);
  485. strcpy(stud[j+1].nume,temp_var);
  486. strcpy(temp_var,stud[j].prenume);
  487. strcpy(stud[j].prenume,stud[j+1].prenume);
  488. strcpy(stud[j+1].prenume,temp_var);
  489. strcpy(temp_var,stud[j].facultatea);
  490. strcpy(stud[j].facultatea,stud[j+1].facultatea);
  491. strcpy(stud[j+1].facultatea,temp_var);
  492. strcpy(temp_var,stud[j].specializarea);
  493. strcpy(stud[j].specializarea,stud[j+1].specializarea);
  494. strcpy(stud[j+1].specializarea,temp_var);
  495. for(z=0;z<10;z++)
  496. {
  497. temp_var2=stud[j].note[z];
  498. stud[j].note[z]=stud[j+1].note[z];
  499. stud[j+1].note[z]=temp_var2;
  500. }
  501. }
  502. }
  503. }
  504. for(i=0;i<count;i++)
  505. {
  506. fprintf(fs,"\n");
  507. fprintf(fs,"Prenume: %s\n",stud[i].prenume);
  508. fprintf(fs,"Nume: %s\n",stud[i].nume);
  509. fprintf(fs,"Facultatea: %s\n",stud[i].facultatea);
  510. fprintf(fs,"Specializarea: %s\n",stud[i].specializarea);
  511. fprintf(fp,"%s ",stud[i].prenume);
  512. fprintf(fp,"%s ",stud[i].nume);
  513. fprintf(fp,"%s ",stud[i].facultatea);
  514. fprintf(fp,"%s ",stud[i].specializarea);
  515. for(j=0;j<10;j++)
  516. {
  517. fprintf(fs,"%d ",stud[i].note[j]);
  518. fprintf(fp,"%d ",stud[i].note[j]);
  519. }
  520. fprintf(fs,"\n");
  521. med=afisare_medie(stud[i].nume,stud[i].prenume);
  522. fprintf(fs,"Media studentului: %d ",med);
  523. fprintf(fp,"%d ",med);
  524. fprintf(fp,"\n");
  525. }
  526. fprintf(fs,"\n");
  527. fprintf(fs,"\n");
  528. fclose(fs);
  529. fclose(fp);
  530. }
  531. void afisare_alfabetica()//FUNCTIE PT AFISAREA IN ORDINE ALFABETICA
  532. {
  533. char temp_var[20];
  534. int temp_var2;
  535. int i,j,z,count=0;
  536. struct node *temp;
  537. temp=primul;
  538. struct studenti
  539. {
  540. char prenume[20],nume[20],facultatea[20],specializarea[20];
  541. int note[10],media;
  542. };
  543. while (temp!=NULL)
  544. {
  545. count++;
  546. temp=temp->adr_urm;
  547. }
  548. struct studenti stud[count];
  549. temp=primul;
  550. for(i=0;i<count;i++)
  551. {
  552. if(temp!=NULL)
  553. {
  554. strcpy(stud[i].prenume,temp->prenume);
  555. strcpy(stud[i].nume,temp->nume);
  556. strcpy(stud[i].facultatea,temp->facultatea);
  557. strcpy(stud[i].specializarea,temp->specializarea);
  558. for(j=0;j<10;j++)
  559. {
  560. stud[i].note[j]=temp->note[j];
  561. }
  562. }
  563. temp=temp->adr_urm;
  564. }
  565. for(i=0;i<count-1;i++)
  566. {
  567. for(j=0;j<count-i-1;j++)
  568. {
  569. if(strcmp(stud[j].nume,stud[j+1].nume)>0)
  570. {
  571. strcpy(temp_var,stud[j].nume);
  572. strcpy(stud[j].nume,stud[j+1].nume);
  573. strcpy(stud[j+1].nume,temp_var);
  574. strcpy(temp_var,stud[j].prenume);
  575. strcpy(stud[j].prenume,stud[j+1].prenume);
  576. strcpy(stud[j+1].prenume,temp_var);
  577. strcpy(temp_var,stud[j].facultatea);
  578. strcpy(stud[j].facultatea,stud[j+1].facultatea);
  579. strcpy(stud[j+1].facultatea,temp_var);
  580. strcpy(temp_var,stud[j].specializarea);
  581. strcpy(stud[j].specializarea,stud[j+1].specializarea);
  582. strcpy(stud[j+1].specializarea,temp_var);
  583. for(z=0;z<10;z++)
  584. {
  585. temp_var2=stud[j].note[z];
  586. stud[j].note[z]=stud[j+1].note[z];
  587. stud[j+1].note[z]=temp_var2;
  588. }
  589. }
  590. }
  591. }
  592. for(i=0;i<count;i++)
  593. {
  594. printf("\n");
  595. printf("Nume: %s\n",stud[i].nume);
  596. printf("Prenume: %s\n",stud[i].prenume);
  597. printf("Facultatea: %s\n",stud[i].facultatea);
  598. printf("Specializarea: %s\n",stud[i].specializarea);
  599. for(j=0;j<10;j++)
  600. {
  601. printf("%d ",stud[i].note[j]);
  602. }
  603. }
  604. printf("\n");
  605. printf("\n");
  606. }
  607. void afisare_nr_studenti()//FUNCTIE PENTRU CONTORIZAREA NUMARULUI DE STUDENTI
  608. {
  609. struct node *temp;
  610. temp=primul;
  611. int count=0;
  612. while (temp!=NULL)
  613. {
  614. count++;
  615. temp=temp->adr_urm;
  616. }
  617. printf("NUMARUL DE STUDENTI DIN LISTA ESTE : %d ",count);
  618. printf("\n\n");
  619. }
  620. void get_student()//FUNCTIE PENTRU IMPORTAREA STUDENTIILOR DIN FISIER
  621. {
  622. FILE *fs;
  623. fs=fopen("studenti_backup.txt","r");
  624. char num[20],pren[20],fac[20],spec[20],buf[1000];
  625. int note[10],i;
  626. while(fgets(buf, 1000, fs)!= NULL)
  627. {
  628. printf("%s",buf);
  629. strcpy(pren,strtok(buf," "));
  630. strcpy(num,strtok(NULL, " "));
  631. strcpy(fac,strtok(NULL," "));
  632. strcpy(spec,strtok(NULL," "));
  633. for(i=0;i<10;i++)
  634. {
  635. note[i]=atoi(strtok(NULL," "));
  636. }
  637. inserare_note_multiple_sfarsit(pren,num,fac,spec,note);
  638. }
  639. fclose(fs);
  640. }
  641. void get_sudent_alfabetic()//FUNCTIE PENTRU IMPORTAREA STUDENTIILOR DIN FISIERUL ORDONAT ALFABETIC
  642. {
  643. FILE *fs;
  644. fs=fopen("studenti_alfabetic_backup.txt","r");
  645. char num[20],pren[20],fac[20],spec[20],buf[1000];
  646. int note[10],i;
  647. while(fgets(buf, 1000, fs)!= NULL)
  648. {
  649. printf("%s",buf);
  650. strcpy(pren,strtok(buf," "));
  651. strcpy(num,strtok(NULL, " "));
  652. strcpy(fac,strtok(NULL," "));
  653. strcpy(spec,strtok(NULL," "));
  654. for(i=0;i<10;i++)
  655. {
  656. note[i]=atoi(strtok(NULL," "));
  657. }
  658. inserare_note_multiple_sfarsit(pren,num,fac,spec,note);
  659. }
  660. fclose(fs);
  661. }
  662. void inserare_note_multiple_sfarsit(char pren[20],char num[20],char fac[20],char spec[20],int note[10])
  663. {
  664. int i;
  665. struct node *temp;
  666. struct node *traverse;
  667. traverse=primul;
  668. temp=createNode();
  669. strcpy(temp->nume,num);
  670. strcpy(temp->prenume,pren);
  671. strcpy(temp->facultatea,fac);
  672. strcpy(temp->specializarea,spec);
  673. for(i=0;i<10;i++)
  674. {
  675. temp->note[i]=note[i];
  676. }
  677. if(primul==NULL)
  678. {
  679. primul=temp;
  680. }
  681. else
  682. {
  683. while(traverse->adr_urm!=NULL)
  684. {
  685. traverse=traverse->adr_urm;
  686. }
  687. traverse->adr_urm=temp;
  688. }
  689. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement