I am trying to make a program which contains the contents of a file and relates its contents to a structure because it has two fields that I want to save, the first field that contains the character and the second field that contains the code of that character . For example:
P: 00 N: 01 Z: 10
My problem is that the program must save any type of character, including the end of line character (\ n), in that case being two complicates everything. In these moments I do the reading with "fscanf (dictionary,"% c:% s ", letter, code);" but in the aforementioned case, I read the "\" as a character and the "n" as a different one. I thought about reading character character but I can not find the way to relate it later with the structure. If you could help me with some idea I would appreciate it. I leave the code that I currently use:
void guarda_diccionario(char diccionariotxt[20]){
int i=0, nro_elementos=0;
FILE * diccionario;
diccionario = fopen(diccionariotxt, "r"); //Abrimos el diccionario para asignar cada campo a la estructura.
if(!diccionario){
printf("Archivo invalido...\n");
return;
}
if(diccionario != NULL){
while(!feof(diccionario)){ //Empieza a guardar cada campo.
fscanf(diccionario, "%c:%s", &nodo[nro_elementos].letra,&nodo[nro_elementos].codigo);
nro_elementos++;
}
fclose(diccionario);
}
}