Hi cpp-Community,
until yet I got every problem solved with just reading posts, but now I can't find any user that had the same problem and I hope you can help me :-)
I just want to read in a wordlist. Normally this shouldn't be a problem, but this time it is!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <fstream>
#include <windows.h>
using namespace std;
int main(int argv, char* argc[])
{
//Info: There are 1275 Lines - The longest strings have 9 chars
ifstream wl;
wl.open(L"wordlist.txt");
char buffer[1275][10];
ZeroMemory(&buffer, sizeof(buffer));
for (int i=0; i<1275; i++)
{
wl.getline(buffer[i], 9, '\n');
cout << buffer[i] << endl;
}
return 0;
}
| |
The compilation is no problem. But when I try to execute the program in cmd I just see some words (the first 971 (6486 chars)) and after this instead of words just empty lines.
Also when I execute it with the parameter >> test.txt there are 971 lines with words (in line 971 the last char of the word is missing) and after this there are a lot of empty lines...
To solve the problem I already tried to split the array like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <fstream>
#include <windows.h>
using namespace std;
int main(int argv, char* argc[])
{
//Info: There are 1275 Lines - The longest strings have 9 chars
ifstream wl1,wl2,wl3;
wl1.open(L"wl1.txt");
wl2.open(L"wl2.txt");
//wl3.open(L"wl3.txt");
char buffer[500][10];
char buffer1[500][10];
//char buffer2[275][10];
ZeroMemory(&buffer, sizeof(buffer));
for (int i=0; i<500; i++)
{
wl1.getline(buffer[i], 9, '\n');
cout << buffer[i] << endl;
wl2.getline(buffer[i+500], 9, '\n');
cout << buffer[i+500] << endl;
//wl3.getline(buffer[i+1000], 9, '\n');
}
//string inc = argc[1];
return 0;
}
| |
The Compiler doesn't find any problem but when I execute it there's a Runtime-Error. Debugging says, that there is a memory corruption.
Can anybody help me? I really don't know how to go on... I just want to write a program that can unscramble 10 words with the help of the wordlist. But if I can't read in the wordlist, the whole program doens't make any sense.
I've 4GB of ram on my computer, so it shouldn't be such a problem for the os to give up some more memory to the prog.
Thanks for reading and thanks in advance for helping me ;-)
Greetz from Germany!
Kevin