I got a new problem over here. I’m trying yo compile a C file which I have a section to read info from a file ‘users.txt’ using the _ptr pointer from the FILE structure. The main problem is when I try to compile the file I got the next error in the terminal: error: ‘FILE’ has no member named ‘_ptr’, and downside the error I got this: make: *** [Makefile:16: main.o] Error 1
This is the Makefile:
ASM_SOURCE = functions.asm
C_SOURCE = main.c
OBJ_FILES = main.o functions.o
EXEC_RELEASE = main_release.bin
EXEC_DEBUG = main_debug.bin
release: $(OBJ_FILES)
gcc -o $(EXEC_RELEASE) $(OBJ_FILES)
debug: $(OBJ_FILES)
gcc -g -o $(EXEC_DEBUG) $(OBJ_FILES)
main.o: $(C_SOURCE)
gcc -c $(C_SOURCE)
functions.o: $(ASM_SOURCE)
nasm -f elf64 -o functions.o $(ASM_SOURCE)
clean:
rm -f $(OBJ_FILES) $(OBJ_FILES) $(EXEC_DEBUG)
And this is the section that I try to run in the C file:
Please ignore the text written in Spanish, I’m coding this with a friend.
// Include section on the top of the file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
// main part of the file
users = calloc(5, sizeof(char*)); // Creando espacio para los usuarios
flag = LECTURA_INCOMPLETA; // Asignando la bandera a 0
i = 0; // Rastrear el valor del buffer main
while(1)
{
// Apuntar al primer char
linea = file.f1 -> _ptr;
n = 0; // Definiendo el valor de estos en 0
//CONTAR HASTA QUE ENCUENTRE UN SALTO DE LINEA, FIN DE LINEA, O QUE YA ENCONTR� EL ULTIMO CARACATER DEL ARCHIVO
while(linea[n] != 'n' && linea[n] != '' && (linea+n+1) != fin)
{
n++;
}
n+=1;
bufferAuxiliar = calloc(n, sizeof(char));
users[i] = calloc(n, sizeof(char)); // Creando espacio en la posici�n i con n longitud de chars
//COPIAR CARACTER POR CARACTER con FGETC, SE PODRIA USAR FGETS
for(j = 0; j < n; j++)
{
bufferAuxiliar[j] = fgetc(file.f1);
users[i][j] = bufferAuxiliar[j]; // Copiando cada char de bufferAuxiliar en Base de datos
//CAMBIAR SALTO DE LINEA POR CARACATER VACIO PARA IMPRESION
if(bufferAuxiliar[j]=='n')
{
bufferAuxiliar[j] = '';
}
if(bufferAuxiliar[j] == EOF)
{
//INDICAR QUE YA SE LLEGO AL FINAL DEL ARCHIVO
flag = LECTURA_COMPLETA;
//SUSTITUIR EOF POR CARACTER VACIO PARA IMPRESION
bufferAuxiliar[j] = '';
}
}
i++; // Limpiando archivo
free(bufferAuxiliar); // Limpiando buffer auxiliar
//TERMINAR DE LEER LINEAS EN EL ARCHIVO
if(flag == LECTURA_COMPLETA)
{
return users; // Retorno de la informaci�n
}
}
}
else
{
return 0; // fail
}
}
else
{
return 0; // fail
}
I hope y’all guys can help me, I would appreciate a lot.
I tried to use the command -l and -L on the Makefile line where the error appears in terminal.
Example:
C_SOURCE = main.c
main.o: $(C_SOURCE)
gcc -L stdio. h-c $(C_SOURCE)