E
Eigenvector
I've been dinking around with this code for a while now and I can't seem to
figure out where the problem lies. The original problem was that I for some
reason or another couldn't allocate few 80,000,000 element arrays. Normally
that shouldn't be a problem but it was. So I tried to do some calloc calls
and everything went south from there.
Essentially I'm trying to read in a big file, stick each line into an array,
then from then on do stuff to it. The do stuff part should work without a
hitch, if I can just get that read in part to work.
Here's the code.
#include <stdio.h>
#include <string.h>
int main()
{
int i=0;
int j=0;
int eof_marker=0;
char *array[1000000];
char *out_array[1000000];
char input_line[80];
FILE *fp;
FILE *fp_out;
/*************************************************/
fp=fopen("/var/tmp/cpu.out", "r");
fp_out=fopen("/var/tmp/cpu.output2", "w");
for (i=0; i<1000000; i++)
array=calloc(80, sizeof(char));
while(fgets(input_line, sizeof(input_line), fp) != NULL)
{
strcat(array, input_line); /* At this line the code core dumps */
i++;
}
eof_marker=i;
}
Please forgive M$'s abominable text parsing, my neat indenting doesn't seem
to have survived intact.
I don't think I understand the logic behind malloc and calloc. I've read
the FAQ and a few past threads from this group already - which is where my
syntax comes from mostly. It just doesn't seem to be clicking.
Rob
figure out where the problem lies. The original problem was that I for some
reason or another couldn't allocate few 80,000,000 element arrays. Normally
that shouldn't be a problem but it was. So I tried to do some calloc calls
and everything went south from there.
Essentially I'm trying to read in a big file, stick each line into an array,
then from then on do stuff to it. The do stuff part should work without a
hitch, if I can just get that read in part to work.
Here's the code.
#include <stdio.h>
#include <string.h>
int main()
{
int i=0;
int j=0;
int eof_marker=0;
char *array[1000000];
char *out_array[1000000];
char input_line[80];
FILE *fp;
FILE *fp_out;
/*************************************************/
fp=fopen("/var/tmp/cpu.out", "r");
fp_out=fopen("/var/tmp/cpu.output2", "w");
for (i=0; i<1000000; i++)
array=calloc(80, sizeof(char));
while(fgets(input_line, sizeof(input_line), fp) != NULL)
{
strcat(array, input_line); /* At this line the code core dumps */
i++;
}
eof_marker=i;
}
Please forgive M$'s abominable text parsing, my neat indenting doesn't seem
to have survived intact.
I don't think I understand the logic behind malloc and calloc. I've read
the FAQ and a few past threads from this group already - which is where my
syntax comes from mostly. It just doesn't seem to be clicking.
Rob