How can I read input consisting of unknown number lines chars(same length) by using scanf("%[^\n]%*c", lines[lineCount])
with loops?
//to learn length (?)
for( ; ;columnnumber++){
scanf("%c",&c);
if(c == '\n'){
break;
}
else{
lines[0][i] = c;
i++;
}
}
lines = realloc(lines,sizeof(char*)*2);
lines[0] = realloc(lines[0],sizeof(char)*columnnumber);
lines[1] = malloc(sizeof(char)*columnnumber);
//tried to use scanf..
while (scanf("%[^\n]%*c", lines[lineCount]) == 1) {
lineCount++;
lines = realloc(lines, (lineCount + 1) * sizeof(char *));
lines[lineCount] = malloc(columnnumber * sizeof(char));
lineCount++;
}
It does not work. I'm new to C programming if there is a easier way to implement my issue I am also open to your suggestions.