int compare (const void *first, const void *second) { if (*(unsigned char*)first > *(unsigned char*)second) return 1; else if (*(unsigned char*)first < *(unsigned char*)second) return -1; else return 0; }
void CLottoDlg::OnButton1() { // TODO: Add your control notification handler code here int idx; unsigned char flag[45]; unsigned char genval = 0; CString *strarray[42] = { &m_edit1,&m_edit2,&m_edit3,&m_edit4,&m_edit5,&m_edit6, &m_edit7,&m_edit8,&m_edit9,&m_edit10,&m_edit11,&m_edit12, &m_edit13,&m_edit14,&m_edit15,&m_edit16,&m_edit17,&m_edit18, &m_edit19,&m_edit20,&m_edit21,&m_edit22,&m_edit23,&m_edit24, &m_edit25,&m_edit26,&m_edit27,&m_edit28,&m_edit29,&m_edit30, &m_edit31,&m_edit32,&m_edit33,&m_edit34,&m_edit35,&m_edit36, &m_edit37,&m_edit38,&m_edit39,&m_edit40,&m_edit41,&m_edit42 };
unsigned char row[42]; memset(flag, 0x00, sizeof(unsigned char) * 45); srand(time(NULL));
for(idx = 0 ;idx < 30;idx++) { do { genval = rand() % 45; } while(flag[genval] != 0); flag[genval] = 1; row[idx] = genval; }
for(idx = 0; idx < 5; idx++) { qsort(row + (idx * 6), 6, sizeof(char), compare); }
for(idx = 0; idx < 30; idx++) { strarray[idx]->Format("%d",row[idx] + 1); }
UpdateData(FALSE); } |