ok so I can get realloc work for a 1d array.
but I'm fully confused with 2d arrays...
this is waht I need:
array[n][255]
while n iterates every single time a new line is read via
"while(fgets(puffer,LENGTH,filein))"
Code:
#include <stdio.h>
#include <stdlib.h>
#include <String.h>
#define LENGTH 255
int main()
{
int i=0;
char **str2d = malloc(sizeof(char*));
str2d[0] = malloc(LENGTH*sizeof(char));
FILE *filein;
FILE *fileout;
char puffer[LENGTH];
filein=fopen("namein.txt","r");
fileout=fopen("nameout.txt", "a");
fgets(puffer,LENGTH,filein);
strcpy(str2d[0], puffer);
while(fgets(puffer,LENGTH,filein))
{
//SOMEHOW REALLOCATE str2d as of str2d[i+1][255] :)
strcpy(str2d[i], puffer);
i++;
}
return 0;
}
could you by any chance give me a hint or pseudo code for the realloc part? :/
can I use realloc at all? or do I need a new function in which I write a complete new array and copy paste the old one?
if that's the case, guess it's better to use lists then no? :/
thanks in advance!