Problem when counting data

-1

My problem is this, I have to count the data of a text file that are separated by a line break. The problem is that when I run it, I get 0 data.

I enclose the code that I wrote, I do not know where the error may be.

#include "head.h"

int main()
{
char aux1,aux2,aux3[7];
int contador=0, j=0, n=0, i=0, t=0;
//Cargando datos
FILE *p;
p=fopen("Estadistica-Localidades-Mendoza.txt","r");
//Comprobando si existe el archivo
if (p==NULL){
    printf("El archivo no existe o no se pudo leer...\n");
    system("pause");
    exit(0);
}
else{

    while (!feof(p)){
        aux1 = fgetc(p);
        if (aux2=='\n')
        {
            contador++;
        }
    }
}
printf("Cantidad de datos: %d\n",contador);
    
asked by Fernando Withmore 27.11.2017 в 22:29
source

1 answer

1

Mmmm in this part:

while (!feof(p)){
    aux1 = fgetc(p);
    if (aux2=='\n')
    {
        contador++;
    }
}

should not be if (aux1 == '\ n') ??? Where are you assigning aux2?

    
answered by 27.11.2017 / 22:33
source