I've written some C code (not a C pro 'though), which is supposed to be as fast as possible. The algorithm is finished and I'm pleased with it's speed. But before it starts, I have to get some information from a text file, which is way to slow.
Right now the processing of the text file needs about 3 seconds for bigger files, while the same file is processed by Java code in less than 1 second, because Java has premade methods like readline() in it's framwork which alone contains more than 100 lines of pure code.
Is there any comparable Framework for C? I couldn't find anything on Google, because no matter how I rephrased my search requests I would get nothing, but tutorials on how to user fopen()...
If you wonder why I don't use Java then: The algorithm itself is way faster in C.
Here is the code I use in C. What needs to be done is to process a .cnf file in DINMACS format.
while ((temp = fgetc(fp)) != EOF)
{
if (temp == 'c')
{
//evtl. im Labor auf 13 ändern
while ((temp =fgetc(fp)) != 10 && temp != EOF);
}
if (temp == 'p')
{
while ((temp =fgetc(fp)) < '0' || temp > '9');
while (temp != 32)
{
variablen= (variablen * 10) + (temp - '0');
temp=fgetc(fp);
}
while ((temp =fgetc(fp)) < '0' || temp > '9');
while ((temp!= 32) && (temp != 10 ) )
{
klauseln= (klauseln * 10) + (temp - '0');
temp=fgetc(fp);
}
while ((temp != 10) && (temp != EOF))
{
temp=fgetc(fp);
}
break;
}
}
phi = (int *) malloc(klauseln * variablen * sizeof(int));
int zaehler2 = 0;
for (int j = 0; j < klauseln; ++j)
{
for (int i = 0; i < variablen; ++i)
{
phi[zaehler2++] = 0;
}
}
int zeile = 0;
while ((temp = fgetc(fp)) != EOF)
{
if (temp == 'c')
{
while ((temp =fgetc(fp)) != 10 && temp != EOF);
}
else
{
while (temp != '0')
{
int neg = 1;
int wert = 0;
while (temp != 32)
{
if (temp == '-')
{
neg = -1;
}
else
{
wert = (wert * 10) + (temp - '0');
}
temp = fgetc(fp);
}
phi[wert - 1 + zeile] = neg;
temp = fgetc(fp);
}
zeile = zeile + variablen;
temp = fgetc(fp);
}
}