i trying to input the text from a text file into a byte buff[]. When i did this byte buf1[] = word; it will prompt me with "initializer fails to determine size of `buf1' " and invalid initializer error. How am i able to pass in the text of my text file into byte buf1[]?
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <fstream>
using namespace std;
typedef unsigned char byte;
byte *rotlexcmp_buf = NULL;
int rottexcmp_bufsize = 0;
int rotlexcmp(const void *l, const void *r)
{
int li = *(const int*)l,
ri = *(const int*)r,
ac = rottexcmp_bufsize;
if (li == ri) return 0;
while (rotlexcmp_buf[li] == rotlexcmp_buf[ri])
{
li = (li + 1) % rottexcmp_bufsize;
ri = (ri + 1) % rottexcmp_bufsize;
if (--ac == 0) return 0;
}
return (rotlexcmp_buf[li] > rotlexcmp_buf[ri]) ? 1 : -1;
}
void bwt_encode(byte *buf_in, byte *buf_out, int size, int *primary_index)
{
int indices[size];
int i;
for (i = 0; i < size; i++)
indices[i] = i;
rotlexcmp_buf = buf_in;
rottexcmp_bufsize = size;
qsort(indices, size, sizeof(int), rotlexcmp);
for (i = 0; i < size; i++)
{
buf_out[i] = buf_in[(indices[i] + size - 1) % size];
if (indices[i] == 0) *primary_index = i;
}
}
void bwt_decode(byte *buf_in, byte *buf_out, int size, int primary_index)
{
int buckets[256];
int i,j,sum;
int indices[size];
memset(buckets, 0, sizeof(buckets));
for (i = 0; i < size; i++)
{
indices[i] = buckets[buf_in[i]];
buckets[buf_in[i]]++;
}
sum = 0;
for (i = 0; i < 256; i++)
{
register int __t = buckets[i];
buckets[i] = sum;
sum += __t;
}
j = primary_index;
for (i = size - 1; i >= 0; i--)
{
buf_out[i] = buf_in[j];
j = buckets[buf_in[j]] + indices[j];
}
}
int main()
{
ifstream fin;
fin.open("Dec of Ind.txt");
string word;
while(getline(fin,word))
{
//cout<<word;
byte buf1[] = word;
int size = strlen((const char*)buf1);
byte buf2[size];
byte buf3[size];
int primary_index;
bwt_encode(buf1, buf2, size, &primary_index);
bwt_decode(buf2, buf3, size, primary_index);
assert(!memcmp (buf1, buf3, size));
printf("Result is the same as input, that is: <%.*s>\n", size, buf3);
//Print out encode/decode results:
printf("Input : <%.*s>\n", size, buf1);
printf("Encoded: <%.*s>\n", size, buf2);
printf("Decoded: <%.*s>\n", size, buf3);
}
cout<<endl;
/*
byte buf1[] = "Polska Wikipedia";
int size = strlen((const char*)buf1);
byte buf2[size];
byte buf3[size];
int primary_index;
bwt_encode(buf1, buf2, size, &primary_index);
bwt_decode(buf2, buf3, size, primary_index);
assert(!memcmp (buf1, buf3, size));
printf("Result is the same as input, that is: <%.*s>\n", size, buf3);
// Print out encode/decode results:
printf("Input : <%.*s>\n", size, buf1);
printf("Encoded: <%.*s>\n", size, buf2);
printf("Decoded: <%.*s>\n", size, buf3);
*/
fin.close();
system("pause");
return 0;
}