having a problem when trying to print specific lines of a .txt file.
The contents of the file are
1ºAmsterdao
1.1 PDI
Casa de Anne Frank
-Descricao: Museu biografico localizado na cidade de Amsterdao, capital dos Paises Baixos.
-Horario de funcionamento: Abertura*7h Fecho*19h
1.2 PDI
Museu Van Gogh
-Descricao: Museu em Amsterdao, nos Paises Baixos.
-Horario de funcionamento: Abertura*8h Fecho*18h
1.3 PDI
Museu da Heineken
-Descricao: Visita interativa pela historia da conhecida marca numa antiga cervejaria que termina numa sala de degustaçao.
-Horario de funcionamento: Abertura*10h Fecho*19
2ºBangkok
2.1 PDI
Grande Palacio de Bangkok
-Descricao: Conjunto de edificios em Bangkok, Tailandia, que serviu como residencia oficial do rei de Tailandia.
-Horario de funcionamento: Abertura*8h Fecho*15h
. . .
And it goes up to the 20º. What I'm trying to print, is the first letter of the word in every line with the "2ºBangkok" format. The issue is that the file can me modified and can be added more of the "PDI's" like 1.4, 1.5 etc. so there is no way to know how many lines are in between.
The way I'm trying to go about, is to get each char of a line, use atoi(), and then compare it to the number of line i printed earlier, so it will only print when the number is bigger.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 500
int main ()
{
FILE *fp = fopen("save_projeto.txt", "r");
char s[MAX_LENGTH];
int numero;
int numero_2;
while (!feof(fp)) {
fscanf(fp, "%d", &numero);
printf("%d", numero);
fgets(s, MAX_LENGTH, fp);
numero_2 = s[0];
printf("%c\n", s[1]);
while(numero_2 != (numero + 1)){
fgets(s, MAX_LENGTH, fp);
numero_2 = s[0];
atoi(numero_2);
}
}
fclose(fp);
}
The output i expected was "1A \n 2B \n 3C...", and instead, the output I'm getting is "1A \n".