Answer the question
In order to leave comments, you need to log in
Where could you not see?
It was necessary to write a program that reads words from a file, and then calculate the address from these words using the hash function and display the hashing results. Initially, it was necessary to write a program in Pascal, in fact, it works properly on it, but trying to write it using c + + errors pop up at the compilation stage, here is one of them:
First stage exception handling at 0x6E1808A5 (msvcr120d.dll) in Project7.exe: 0xC0000005: Access violation while reading at 0xCCCCCCCC.
Unhandled exception at 0x6E1808A5 (msvcr120d.dll) in Project7.exe: 0xC0000005: Access violation while reading at 0xCCCCCCCC.
What can be a snag?
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
const int n = 15;
int hashStr(char str[n]){
unsigned int i;
int key = 0;
for (i = 1; i < strlen(str); i++){
key += (int)str[i];
}
return (key % n) + 1;
}
int main()
{
setlocale (LC_ALL, "RUS");
bool b;
unsigned int count, i;
string rec[n];
fstream F;
char s[n];
int j;
count = 0;
F.open("test.txt");
for (j = 1; j < n; j++){
rec[j] = "";
}
if (F){
while (!F.eof()){
b = false;
F >> s;
j = hashStr(s);
if (rec[j] == "" || s == rec[j]) {
rec[j] = s;
b = true;
}
else{
for (count = 1; count <= n; count++){
if (rec[(j + count) % n + 1] == "" || s == rec[(j + count) % n + 1]){
j = (j + count) % n + 1;
rec[j] = s;
b = true;
break;
}
}
}
if (b == true){
cout << s << " Найдено в позиции " << j << " количество сравнений " << count <<endl ;
}
else{
cout << s << " не найдено , количество сравнений "<< count << endl;
count = 0;
}
}
F.close();
}
else cout << " Файл не существует" << endl;
system("pause");
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question