Fellows,
Please help me to get thru this error and get it running:
error:
"filetolinkedlist.c", line 35: error #2137: expression must be a modifiable
lvalue
lista->line=lineinput;
code is:
Code:
#include <stdio.h>
#include <stdlib.h>
FILE *fr;
char filename[100];
struct filecontents{
char line[200];
struct filecontents *next;
};
void printfilecontents(struct filecontents *lista)
{
int contador=0;
if (lista == NULL)
{
printf("0 registros\n");
}
while (lista != NULL)
{
printf("print %p %p %d\n", lista, lista->next, lista->line);
lista = lista->next;
}
printf("%d registros\n", contador);
}
struct filecontents *add(struct filecontents **p, char lineinput[20])
{
struct filecontents *lista = malloc(sizeof(struct filecontents));
if (lista == NULL)
return NULL;
lista->next = *p;
*p = lista;
lista->line=lineinput;
return *p;
}
main(){
char line[200];
struct filecontents *lista = NULL;
printf("Informe o nome do arquivo que deseja importar para a lista: ");
scanf("%s", filename);
fflush(stdin);
fr = fopen(filename, "rt");
while(fgets(line, 200, fr)){
add(&lista, line);
}
fclose(fr);
printfilecontents(lista);
}
Please someone help me fix it. I just need to get it running, no best practices tips are needed.
Thank you.