Created
April 5, 2018 14:22
-
-
Save bossxomlut/e0417324860bf31b8405cb60f2858b1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<conio.h> | |
| #include <fcntl.h> //_O_U16TEXT | |
| #include <io.h> //_setmode() | |
| #include <string.h> | |
| //#include "khaibao.h" | |
| #pragma warning (disable: 4996) | |
| struct SV | |
| { | |
| char MSSV[10]; | |
| wchar_t HoVaTen[30]; | |
| wchar_t Khoa[30]; | |
| int Khoa_s; | |
| char NgaySinh[10]; | |
| wchar_t AnhCaNhan[30]; | |
| wchar_t MoTa[1000]; | |
| wchar_t SoThich[500]; | |
| }; | |
| wchar_t* hamgankytu(wchar_t* a,FILE* fp,int dodai) | |
| { | |
| fgetws(a, dodai ,fp); | |
| return a; | |
| } | |
| int hamdemdodaikhoangkytu(FILE* fp) | |
| { wchar_t c; | |
| int dem=0; | |
| do | |
| { | |
| fwscanf(fp,L"%lc",&c); | |
| dem++; | |
| }while(c!='"'); | |
| return dem; | |
| } | |
| int soluongsv(FILE* fp) | |
| { | |
| int dem=0; | |
| wchar_t c; | |
| while(1) | |
| { | |
| fwscanf(fp,L"%lc",&c); | |
| if(c=='\n') | |
| { | |
| dem++; | |
| } | |
| if(feof(fp)) | |
| { | |
| break; | |
| } | |
| } | |
| return dem+1; | |
| } | |
| void main() | |
| { //khai báo biến | |
| SV svdec[100]; | |
| wchar_t str[255]; | |
| wchar_t c; | |
| int sosv; | |
| int dem; | |
| //khai báo | |
| //-------------------------------- | |
| _setmode(_fileno(stdout), _O_U16TEXT); //needed for output | |
| _setmode(_fileno(stdin), _O_U16TEXT); //needed for input | |
| //---------------- | |
| FILE* fp=_wfopen(L"tep.csv",L"r,ccs=UTF-8"); // mở tệp | |
| //---------------- | |
| if(!fp) | |
| { | |
| wprintf(L"Không thể mở được tệp!\n"); | |
| return; | |
| } | |
| fflush(fp); | |
| //kiểm tra mở được không------- | |
| sosv=soluongsv(fp); // đếm số sv | |
| rewind(fp); //trả về đầu tệp | |
| for(int i=0;i<sosv;i++) | |
| { | |
| do | |
| { | |
| fwscanf(fp,L"%lc",&c); | |
| fgetws((wchar_t*)svdec[i].MSSV,dem=hamdemdodaikhoangkytu(fp),fp); | |
| fgetws((wchar_t*)svdec[i].HoVaTen,dem=hamdemdodaikhoangkytu(fp),fp); | |
| fgetws((wchar_t*)svdec[i].Khoa,dem=hamdemdodaikhoangkytu(fp),fp); | |
| fgetws((wchar_t*)svdec[i].Khoa_s,dem=hamdemdodaikhoangkytu(fp),fp); | |
| fgetws((wchar_t*)svdec[i].NgaySinh,dem=hamdemdodaikhoangkytu(fp),fp); | |
| fgetws((wchar_t*)svdec[i].AnhCaNhan,dem=hamdemdodaikhoangkytu(fp),fp); | |
| fgetws((wchar_t*)svdec[i].MoTa,dem=hamdemdodaikhoangkytu(fp),fp); | |
| fgetws((wchar_t*)svdec[i].SoThich,dem=hamdemdodaikhoangkytu(fp),fp); | |
| }while(c!='\n'); | |
| } | |
| /*if(c== '"') | |
| { | |
| fgetws((wchar_t*)svdec.MSSV,10,fp); | |
| } | |
| wprintf(L"%s\n",svdec.MSSV); */ | |
| //wprintf(L"%ls",str); | |
| fclose(fp);//đóng tệp | |
| getch(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment