Помогите пожалуйста, переделать программу чтобы компилировалась на dev_cpp, прога на С# В долгу не останусь, если что пишите в асю 803-866 Код | #include <vcl.h> #include <iostream.h> #pragma hdrstop
struct THashTable{ // структура хэщ-таблицы char string[50]; int koliziya; // добавь еще какое-нибудь поля, если необходимо };
THashTable HashTable[20];
static int index = 0;
#pragma argsused int Crc32(unsigned char *buf, unsigned long len) { unsigned long crc_table[256]; unsigned long crc;
for (int i = 0; i < 256; i++) { crc = i; for (int j = 0; j < 8; j++) crc = crc & 1 ? (crc >> 1) ^ 0xEDB88320UL : crc >> 1;
crc_table[i] = crc; };
crc = 0xFFFFFFFFUL;
while (len--) crc = crc_table[(crc ^ *buf++) & 0xFF] ^ (crc >> 8);
return (crc ^ 0xFFFFFFFFUL) % 10; // получаем адресс ячейки хэш-таблицы. };
void FillHash(int index, char* arg) { if (strcmp(HashTable[index].string, "pusto") == 0) strcpy(HashTable[index].string, arg); else { ++HashTable[index].koliziya; ++index; FillHash(index, arg); } }
void print() { for (int i = 0; i<10; i++){ printf("ocherednaya stroka %s \n", HashTable[i].string); printf("kolizii %i \n\n" , HashTable[i].koliziya); } }
void search(char *arg) { bool Naideno = false; while (!Naideno) { index = Crc32(arg, sizeof(arg)); if ( strcmp(HashTable[index].string, arg) == 0) { Naideno = true; printf("stroka naidena, ee index = %i", index); } else { if (strcmp(HashTable[index].string, "pusto") == 0) { Naideno = true; printf("stroka NE naidena"); } Naideno = true; printf("jopa"); } } }
void add(char *arg) { index = Crc32(arg, sizeof(arg)-1); FillHash(index, arg); }
void del(int number) { strcpy(HashTable[number].string, "pusto"); HashTable[number].koliziya = 0; }
int main(int argc, char* argv[]) {
FILE *fin; fin = fopen("in.txt", "r"); char rbuf[127] = "pusto";
for (int i = 0; i < 10; i++){ strcpy(HashTable[i].string, rbuf); HashTable[i].koliziya = 0; }
while(!feof(fin)) // заполнение хэш-таблицы строками из файла { fgets(rbuf, sizeof(rbuf)-1, fin); index = Crc32(rbuf, sizeof(rbuf)-1); FillHash(index, rbuf); }
fclose(fin); cin.get(); cin.get(); return 0; } //---------------------------------------------------------------------------
|
|