O
OziRus
Hi,
I've char* array that I defined like char *str[150]. I want to read
from a file, that contains names in each row, and assign them to my str
char * array.
m is a char array, f is a file pointer and counter is my variable that
contains number of names in my file;
When I write;
while(fgets(m,100,f)!=NULL) {
printf("%s",m)
}
code. It gets and writes all my names onto screen but;
When I recode it like;
while(fgets(m,100,f)!=NULL) {
str[counter]=m;
counter--;
}
and try print str[1] ve str[2] to screen It always print my last
elements for 2 times.
For example:
File: John, Alp, Liz, Sema
First code writes;
John, Alp, Liz, Sema
With second code and printfs:
Sema, Sema
How can I fix it? Thanks so much...
I've char* array that I defined like char *str[150]. I want to read
from a file, that contains names in each row, and assign them to my str
char * array.
m is a char array, f is a file pointer and counter is my variable that
contains number of names in my file;
When I write;
while(fgets(m,100,f)!=NULL) {
printf("%s",m)
}
code. It gets and writes all my names onto screen but;
When I recode it like;
while(fgets(m,100,f)!=NULL) {
str[counter]=m;
counter--;
}
and try print str[1] ve str[2] to screen It always print my last
elements for 2 times.
For example:
File: John, Alp, Liz, Sema
First code writes;
John, Alp, Liz, Sema
With second code and printfs:
Sema, Sema
How can I fix it? Thanks so much...