How do I get into several different files

0

Good night, I have a doubt, I have a program that will receive several files of type nome.txt , and I must count how many characters there are inside the file, I tried to make a prototype but the doubt is in how I will add this using% how do I get a file in txt and then check the characters ??

The following is the code below:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int counter = 0;
    FILE* file = NULL;
    char * arquivo = NULL;
    char frases;
    size_t aux = 0;

    getline(&arquivo,&aux, stdin);

    file = fopen("arquivo", "r" );

    while(fgetc(file) != EOF)
        counter++;

    printf("%d", counter);

    fclose(file);

}
    
asked by anonymous 07.06.2015 / 04:25

1 answer

0
file = fopen("arquivo", "r" );

This instruction in your program will open the file named "arquivo" ; will not open the file with the name that the user entered and that is contained in the arquivo variable. For this you need to do

file = fopen(arquivo, "r");

In addition, according to the POSIX manual for getline() , kbd> ENTER that the user used. You should remove this ENTER before opening the file.

To do with several different files you have to cycle. And put the filename request, file opening, character count, and file closing within that cycle.

    
07.06.2015 / 09:17