#include "MyLib.h"Idź do kodu źródłowego tego pliku.
Definicje | |
| #define | _WIN32 |
Funkcje | |
| int | strptime (char *strDat, const char *format, struct tm *tm) |
| time_t | strToTime (char *strDat) |
| void | readCSV (char *nazwaCSV, int *N, struct TLst Lst[]) |
| void | sortProc1 (int N, struct TLst *Lst) |
| int | cmpIm (const void *m1, const void *m2) |
| int | cmpNa (const void *m1, const void *m2) |
| void | sortProc2 (void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) |
| void | wyswietlLst (int N, struct TLst *Lst) |
| int | main () |
| int cmpIm | ( | const void * | m1, | |
| const void * | m2 | |||
| ) |
| int cmpNa | ( | const void * | m1, | |
| const void * | m2 | |||
| ) |
| int main | ( | ) |
Definicja w linii 242 pliku sort.c.
Odwołuje się do cmpIm(), cmpNa(), readCSV(), sortProc1(), sortProc2() i wyswietlLst().
00243 { 00244 struct TLst Lst[100]; 00245 int N; 00246 00247 readCSV("dane.csv", &N, Lst); 00248 puts("####################"); 00249 printf("N: %i\n", N); 00250 puts("== SORTOWANIE ========================="); 00251 puts(" imie nazwisko ocena data\n"); 00252 puts("- surowe ------------------------------"); 00253 wyswietlLst(N, Lst); 00254 puts("- po dacie ----------------------------"); 00255 sortProc1(N, Lst); 00256 wyswietlLst(N, Lst); 00257 puts("- po imieniu --------------------------"); 00258 sortProc2(Lst, N, sizeof(struct TLst), cmpIm); 00259 wyswietlLst(N, Lst); 00260 puts("- po nazwisku -------------------------"); 00261 qsort(Lst, N, sizeof(struct TLst), cmpNa); 00262 wyswietlLst(N, Lst); 00263 puts("---------------------------------------"); 00264 /* 00265 #ifdef _WIN32 00266 system("PAUSE"); 00267 #endif 00268 */ 00269 return 0; 00270 }
| void readCSV | ( | char * | nazwaCSV, | |
| int * | N, | |||
| struct TLst | Lst[] | |||
| ) |
Definicja w linii 88 pliku sort.c.
Odwołuje się do TLst::Data, TLst::Ocena, parserCSV(), separator, sepStr i strToTime().
Odwołania w main().
00089 { 00090 char buf[1024],*wr,*ws[32],*wt[3]; 00091 FILE *fDane; 00092 int i,n,OK; 00093 00094 fDane = fopen(nazwaCSV, "r"); 00095 *N = 0; 00096 n = 30; 00097 if( fDane==NULL ) 00098 { 00099 perror(nazwaCSV); 00100 exit(-1); 00101 } 00102 printf("z pliku \"%s\"\n", nazwaCSV); 00103 while( fgets(buf,1024,fDane)!=NULL ) 00104 { 00105 n = 3; 00106 OK = 1; 00107 if( parserCSV(buf, ws, n, separator)!=n ) 00108 continue; 00109 for(i=0; i<4 && OK ; i=i+1) 00110 { 00111 if( parserCSV(ws[i], wt, 2, sepStr)==2 ) 00112 { 00113 switch( i ) 00114 { 00115 case 0: 00116 strcpy(Lst[*N].Im, wt[1]); 00117 break; 00118 case 1: 00119 strcpy(Lst[*N].Na, wt[1]); 00120 break; 00121 default: 00122 puts("ERROR: zly rekord !?"); 00123 OK = 0; 00124 break; 00125 } 00126 } 00127 else 00128 { 00129 switch( i ) 00130 { 00131 case 2: 00132 wr = strchr(ws[i],','); 00133 if( wr!=NULL) 00134 *wr = '.'; 00135 Lst[*N].Ocena = strtod(ws[i],&wr); 00136 if( *wr!='\0' ) 00137 { 00138 OK = 0; 00139 } 00140 break; 00141 case 3: 00142 Lst[*N].Data = strToTime(ws[i]); 00143 if( Lst[*N].Data==0 ) 00144 { 00145 OK = 0; 00146 } 00147 break; 00148 default: 00149 puts("ERROR: zly rekord !?"); 00150 OK = 0; 00151 break; 00152 } 00153 } 00154 } 00155 if( OK ) 00156 { 00157 *N = *N+1; 00158 } 00159 } 00160 fclose(fDane); 00161 }
| void sortProc1 | ( | int | N, | |
| struct TLst * | Lst | |||
| ) |
Definicja w linii 163 pliku sort.c.
Odwołuje się do TLst::Data.
Odwołania w main().
00164 { 00165 struct TLst LstR; 00166 int i,j; 00167 00168 for(i=0; i<N; i=i+1) 00169 { 00170 for(j=i+1; j<N; j=j+1) 00171 { 00172 // if( 0<strcmp((Lst+i)->Na,(Lst+j)->Na) ) 00173 if( (Lst+i)->Data > (Lst+j)->Data ) 00174 { 00175 memmove(&LstR,Lst+j,sizeof(struct TLst)); 00176 memmove(Lst+j,Lst+i,sizeof(struct TLst)); 00177 memmove(Lst+i,&LstR,sizeof(struct TLst)); 00178 } 00179 } 00180 } 00181 }
| void sortProc2 | ( | void * | base, | |
| size_t | nmemb, | |||
| size_t | size, | |||
| int(*)(const void *, const void *) | compar | |||
| ) |
Definicja w linii 203 pliku sort.c.
Odwołania w main().
00204 { 00205 char *buf,*ws1,*ws2,m[1024]; 00206 int i,j; 00207 00208 buf = (char *)base; 00209 for(i=0; i<nmemb; i=i+1) 00210 { 00211 for(j=i+1; j<nmemb; j=j+1) 00212 { 00213 ws1 = buf+i*size; 00214 ws2 = buf+j*size; 00215 if( 0<(*compar)(ws1, ws2) ) 00216 { 00217 memmove(m, ws2, size); 00218 memmove(ws2, ws1, size); 00219 memmove(ws1, m, size); 00220 } 00221 } 00222 } 00223 }
| int strptime | ( | char * | strDat, | |
| const char * | format, | |||
| struct tm * | tm | |||
| ) |
Definicja w linii 32 pliku sort.c.
Odwołania w strToTime().
00033 { 00034 char *wr,*ws,*wt,_strDat[15]; 00035 00036 strncpy(_strDat,strDat,12); 00037 _strDat[12] = '\0'; 00038 wr = strchr(_strDat,'-'); 00039 if( wr==NULL ) 00040 { 00041 return 0; 00042 } 00043 *wr = '\0'; 00044 tm->tm_year = strtol(_strDat,&wt,10)-1900; 00045 wr = wr+1; 00046 ws = strchr(wr,'-'); 00047 if( ws==NULL || *wt!='\0' || tm->tm_year<70 || tm->tm_year>137 ) 00048 { 00049 return 0; 00050 } 00051 *ws = '\0'; 00052 tm->tm_mon = strtol(wr,&wt,10)-1; 00053 if( *wt!='\0' || tm->tm_mon<0 || tm->tm_mon>11 ) 00054 { 00055 return 0; 00056 } 00057 ws = ws+1; 00058 tm->tm_mday = strtol(ws,&wt,10); 00059 if( *wt!='\0' || tm->tm_mday<0 || tm->tm_mday>31 ) 00060 { 00061 return 0; 00062 } 00063 return (int)(wt-_strDat); 00064 }
| time_t strToTime | ( | char * | strDat | ) |
Definicja w linii 67 pliku sort.c.
Odwołuje się do strptime().
Odwołania w readCSV().
00068 { 00069 struct tm tm; 00070 time_t T; 00071 char *ws; 00072 00073 memset(&tm,'\0',sizeof(struct tm)); 00074 ws = strpbrk(strDat,"\r\n\t"); 00075 if( ws!=NULL ) 00076 { 00077 *ws = '\0'; 00078 } 00079 if( !strptime( strDat, "%Y-%m-%d", &tm) ) 00080 { 00081 printf("Bledna data: \"%s\" !?\n", strDat); 00082 return 0; 00083 } 00084 T = mktime( &tm); 00085 return T; 00086 }
| void wyswietlLst | ( | int | N, | |
| struct TLst * | Lst | |||
| ) |
Definicja w linii 225 pliku sort.c.
Odwołania w main().
00226 { 00227 char strDat[81]; 00228 struct tm tm; 00229 time_t T; 00230 int i; 00231 00232 for(i=0; i<N; i=i+1) 00233 { 00234 printf("%s\t\t%s\t\t%10.3lf\t", (Lst+i)->Im, (Lst+i)->Na, (Lst+i)->Ocena); 00235 T = (Lst+i)->Data; 00236 memmove(&tm, localtime( &T ), sizeof(struct tm)); 00237 strftime(strDat, 31, "%Y-%m-%d", &tm); 00238 printf("%s\n", strDat); 00239 } 00240 }
1.6.1