简体   繁体   中英

How can i read only certain line from txt file in c?

I have this file and i Want to save in variables only the lines that dont start with //:

// Dimensoes da janela em termo de bolhas (largura e altura)
60 40
// Dimensão da bolha em pixeis (raio)
5
// dl – distancia para avaliação da colisão (percentagem do diametro)
0.95
// Numero de linhas inicias com bolhas
6
// Geração de uma nova linha de bolhas ao fim de N jogadas
10

Im not sure how i can do it. I've tryed with fscanf and fgets but im not doing it right thanks in advance

You can try something like:

FILE * inputFile; 
char str[256];
inputFile = fopen("fileName.txt", "r");
while(fgets(str, 256, inputFile) != NULL) {
    if (str[0] == '/' && str[1] == '/') {
        // Save string here
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM