Im writing a C code to read a file line by line which contains alphabets, CR,LF,'\0'. Below is my attached code sample. I want to store only alphabets from each line to an array such that the numbers of rows in the array equals no of lines in the file and column should be of varying length(depends on the number of character in i-th line).
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *buffer[100];
char temp[128];
int c,i=0,j=0;
int pos=0;
FILE *file;
file = fopen("input", "r");
if (file) {
while ((c = getc(file)) != EOF){
if ((c>=65 && c<=90) || (c>=97 && c<=122))
temp[pos++]=c;
else if(pos>1) {
temp[pos]='\0';
buffer[i]=temp;
printf ("%s\n",temp);
i++;
pos=0;
}
}
}
fclose(file);
while (j<i){
printf("%s\n",buffer[j]);
j++;
}
}
If i run my above code, all my buffer[j] contains same string. Can anyone help me out in figuring what was wrong in the code.