//구조체에 맞는 파일을 읽어들여서 해당변수로 정렬하는 프로그램(정렬시에 스택변수사용시)
//구조체에 맞는 파일을 읽어들여서 해당변수로 정렬하는 프로그램(정렬시에 스택변수사용시)
//구조체에 맞는 파일을 읽어들여서 해당변수로 정렬하는 프로그램(정렬시에 스택변수사용시)
//구조체에 맞는 파일을 읽어들여서 해당변수로 정렬하는 프로그램(정렬시에 스택변수사용시)
//CALL BY VALUE & CALL BY REFERENCE
//CALL BY VALUE & CALL BY REFERENCE
//CALL BY VALUE & CALL BY REFERENCE
//CALL BY VALUE & CALL BY REFERENCE
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct KSEMASTBATCH {
char dataclass[2];
char infoclass[2];
char marketclass;
char stockcode[12];
char serialno[8];
char abbrstockcode[9];
char abbrstocknamekor[40];
char abbrstocknameeng[40];
char senddate[8];
char infodivisiongroupno[5];
char stockgroupid[2];
char isunittrade;
char exclasscode[2];
char facevaluechangeclasscode[2];
char isopenpricebasedstandardprice;
char isrevaluationstockreason[2];
char isstandardpricechangestock;
char israndomendpossibillty;
char ismarketalarmdangernotice;
char marketalarmclasscode[2];
char iscorporategovernancefine;
char ismanagementstock;
char isinsinceritypublicnewsappoint;
char isbackdoorlisting;
char istradestop;
char indexbusinesstypelarge[3];
char indexbusinesstypemedium[3];
char indexbusinesstypesmall[3];
char standardindustrycode[10];
char businesstypekospi200;
char listpricesizecode;
char ismanufactureindustry;
char iskrx100stock;
char isdividendindexstock;
char iscorporategovernanceindexstock;
char investorganclasscode[2];
char iskospi;
char iskospi100;
char iskospi50;
char iskrxsectorindexcar;
char iskrxsectorindexsemiconductor;
char iskrxsectorindexbio;
char iskrxsectorindexfinance;
char iskrxsectorindexit;
char iskrxsectorindexenergychemical;
char iskrxsectorindexsteel;
char iskrxsectorindexnecessary;
char iskrxsectorindexmediacomm;
char iskrxsectorindexconstruction;
char iskrxsectorindexfinanceservice;
char iskrxsectorindexstock;
char iskrxsectorindexship;
char standardprice[9];
char ff;
};
#define SZ_KSEMASTBATCH sizeof(struct KSEMASTBATCH)
#define MAX_KSEMASTBATCH_CNT 1024
int main(int argc, char *argv[])
{
FILE *fp=NULL;
char rbuf[4096];
struct KSEMASTBATCH *kse1[MAX_KSEMASTBATCH_CNT];
struct KSEMASTBATCH *kse2[MAX_KSEMASTBATCH_CNT];
struct KSEMASTBATCH *kse3[MAX_KSEMASTBATCH_CNT];
struct KSEMASTBATCH *kse_src[MAX_KSEMASTBATCH_CNT];
struct KSEMASTBATCH *kse_tmp;
struct KSEMASTBATCH kse_1_address[MAX_KSEMASTBATCH_CNT];
struct KSEMASTBATCH kse_2_address[MAX_KSEMASTBATCH_CNT];
struct KSEMASTBATCH kse_address_tmp;
int ii,kk,mm,ff,jj,cnt;
if(argc != 2)
{
return(-1);
}
if((fp=fopen(argv[1], "rt"))==NULL)
{
return(-1);
}
kk=0;
while(1)
{
memset(rbuf,0x00,sizeof(rbuf));
if(fgets(rbuf, sizeof(rbuf), fp)==NULL) break;
//STACK REGISTER & POINTER REGISTER
//STACK REGISTER & POINTER REGISTER
//STACK REGISTER & POINTER REGISTER
//STACK REGISTER & POINTER REGISTER
memcpy(&kse_1_address[kk], rbuf, SZ_KSEMASTBATCH);
//memcpy(&kse_2_address[kk], rbuf, SZ_KSEMASTBATCH);
kse_2_address[kk] = kse_1_address[kk];
//[kse1 == kse2 == kse3] SAME ADDRESS POINTER
//[kse1 == kse2 == kse3] SAME ADDRESS POINTER
//[kse1 == kse2 == kse3] SAME ADDRESS POINTER
//[kse1 == kse2 == kse3] SAME ADDRESS POINTER
kse1[kk] = &kse_1_address[kk];
kse2[kk] = &kse_1_address[kk];
kse3[kk] = &kse_1_address[kk];
kse_src[kk] = &kse_2_address[kk];
kk++;
if(kk>1000) break;
}
cnt=kk;
if(fp != NULL) fclose(fp);
//ASCENDING SORT BY SYMBOL(POINTER VARIABLE)
//ASCENDING SORT BY SYMBOL(POINTER VARIABLE)
//ASCENDING SORT BY SYMBOL(POINTER VARIABLE)
for(kk=0; kk<cnt; kk++)
{
for(ii=kk+1; ii<cnt; ii++)
{
if(memcmp(kse1[kk]->stockcode,kse1[ii]->stockcode,sizeof(kse1[ii]->stockcode))>0)
{
kse_tmp=NULL;
kse_tmp = kse1[kk];
kse1[kk] = kse1[ii];
kse1[ii] = kse_tmp;
}
}
}
//ASCENDING SORT BY SYMBOL(STACK VARIABLE)
//ASCENDING SORT BY SYMBOL(STACK VARIABLE)
//ASCENDING SORT BY SYMBOL(STACK VARIABLE)
for(kk=0; kk<cnt; kk++)
{
for(ii=kk+1; ii<cnt; ii++)
{
if(memcmp(kse_1_address[kk].stockcode,kse_1_address[ii].stockcode,sizeof(kse_1_address[ii].stockcode))>0)
{
kse_address_tmp = kse_1_address[kk];
kse_1_address[kk] = kse_1_address[ii];
kse_1_address[ii] = kse_address_tmp;
}
}
}
//DESCENDING SORT BY SYMBOL(STACK VARIABLE)
//DESCENDING SORT BY SYMBOL(STACK VARIABLE)
//DESCENDING SORT BY SYMBOL(STACK VARIABLE)
for(kk=0; kk<cnt; kk++)
{
for(ii=kk+1; ii<cnt; ii++)
{
if(memcmp(kse_2_address[kk].stockcode,kse_2_address[ii].stockcode,sizeof(kse_2_address[ii].stockcode))<0)
{
kse_address_tmp = kse_2_address[kk];
kse_2_address[kk] = kse_2_address[ii];
kse_2_address[ii] = kse_address_tmp;
}
}
}
cnt = 5;
for(kk=0; kk<cnt; kk++)
{
printf("(1)[%06x],SYM[%.12s]>>>>[%06x][%.12s],[%06x][%.12s]\n",
kk+1, kse_1_address[kk].stockcode, kse_1_address[kk].stockcode, kse1[kk]->stockcode,
kse1[kk]->stockcode, kse_src[kk]->stockcode, kse_src[kk]->stockcode);
}
for(kk=0; kk<cnt; kk++)
{
printf("(2)[%06x],SYM[%.12s]>>>>[%06x][%.12s],[%06x][%.12s]\n",
kk+1, kse_1_address[kk].stockcode, kse_1_address[kk].stockcode, kse2[kk]->stockcode,
kse2[kk]->stockcode, kse_src[kk]->stockcode, kse_src[kk]->stockcode);
}
for(kk=0; kk<cnt; kk++)
{
printf("(3)[%06x],SYM[%.12s]>>>>[%06x][%.12s],[%06x][%.12s]\n",
kk+1, kse_1_address[kk].stockcode, kse_1_address[kk].stockcode, kse3[kk]->stockcode,
kse3[kk]->stockcode, kse_src[kk]->stockcode, kse_src[kk]->stockcode);
}
for(kk=0; kk<cnt; kk++)
{
printf("(4)[%06x],SYM[%.12s]>>>>[%06x][%.12s],[%06x][%.12s]\n",
kk+1, kse_2_address[kk].stockcode, kse_2_address[kk].stockcode, kse3[kk]->stockcode,
kse3[kk]->stockcode, kse_src[kk]->stockcode, kse_src[kk]->stockcode);
}
return(0);
}
/*결과
C:\Users\Downloads>20 A0011.dat
(1)[000001],SYM[HK0000050325]>>>>[162f21][HK0000050325],[162f21][KR7182490003]
(1)[000002],SYM[KR5707017R97]>>>>[163241][KR5707017R97],[163241][KR7182480004]
(1)[000003],SYM[KR5713017R38]>>>>[163561][KR5713017R38],[163561][KR7181710005]
(1)[000004],SYM[KR571301A1B4]>>>>[163881][KR571301A1B4],[163881][KR7181480005]
(1)[000005],SYM[KR5713027R36]>>>>[163ba1][KR5713027R36],[163ba1][KR7181450008]
(2)[000001],SYM[HK0000050325]>>>>[162f21][HK0000050325],[162f21][KR7182490003]
(2)[000002],SYM[KR5707017R97]>>>>[163241][KR5707017R97],[163241][KR7182480004]
(2)[000003],SYM[KR5713017R38]>>>>[163561][KR5713017R38],[163561][KR7181710005]
(2)[000004],SYM[KR571301A1B4]>>>>[163881][KR571301A1B4],[163881][KR7181480005]
(2)[000005],SYM[KR5713027R36]>>>>[163ba1][KR5713027R36],[163ba1][KR7181450008]
(3)[000001],SYM[HK0000050325]>>>>[162f21][HK0000050325],[162f21][KR7182490003]
(3)[000002],SYM[KR5707017R97]>>>>[163241][KR5707017R97],[163241][KR7182480004]
(3)[000003],SYM[KR5713017R38]>>>>[163561][KR5713017R38],[163561][KR7181710005]
(3)[000004],SYM[KR571301A1B4]>>>>[163881][KR571301A1B4],[163881][KR7181480005]
(3)[000005],SYM[KR5713027R36]>>>>[163ba1][KR5713027R36],[163ba1][KR7181450008]
(4)[000001],SYM[KR7182490003]>>>>[09af21][HK0000050325],[162f21][KR7182490003]
(4)[000002],SYM[KR7182480004]>>>>[09b241][KR5707017R97],[163241][KR7182480004]
(4)[000003],SYM[KR7181710005]>>>>[09b561][KR5713017R38],[163561][KR7181710005]
(4)[000004],SYM[KR7181480005]>>>>[09b881][KR571301A1B4],[163881][KR7181480005]
(4)[000005],SYM[KR7181450008]>>>>[09bba1][KR5713027R36],[163ba1][KR7181450008]
*/
'c 언어 > 고급과정' 카테고리의 다른 글
DOS-HEXA(QUICK VIEW) (0) | 2020.08.07 |
---|---|
포인터변수를 사용한 정렬 & 스택변수 (0) | 2019.10.31 |
HASH TABLE을 이용한 KEY,VALUE 컨트롤(KEY개수 65536개까지) (0) | 2019.10.31 |
포인터변수 + 스택변수를 이용한 해쉬테이블 사용예제(해쉬테이블 2개사용예제) + 수식에 콤마 추가 (0) | 2019.10.31 |
WINDOWS, 아이작스를 이용한 네트웍 헥사 프로그래밍(103) (0) | 2019.10.31 |