What function in C language does it allow to open file .txt
and run other functions in the contents of this .txt
?
What function in C language does it allow to open file .txt
and run other functions in the contents of this .txt
?
In essence it's fopen()
that opens and then has set of functions that are used to manipulate the data and access the contents of the file and finally close the file . But there are a multitude of ways to access files that can meet different needs of this, most operating system-specific APIs. Basic example:
// Abre o arquivo em modo de escrita estendida (leitura/gravação)
// e retorna um ponteiro para um file stream (fluxo de arquivo).
FILE *file = fopen("arquivo.txt", "w+");
char str[101];
// Lê 101 bytes do arquivo texto e joga na variável str.
fscanf(file, "%s", str);
// Exibe em tela o conteúdo lido do arquivo texto.
printf("|%s|\n", str);
// Fecha o arquivo texto.
fclose(file);
I placed GitHub for future reference .
There is nothing ready that opens, loads all the content and makes it available. C does not have this philosophy of "batteries included", you have to do everything you want besides the basics and if you know how to do generically you can use this function in all its applications.