2
I tried the code below, but it didn’t work
The big problem is fscanf placing each character of the text in an array position
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int a;
char texto[1000];
FILE *file;
file = fopen("texto.txt", "r");
//fscanf(file, " %c", &texto);
fscanf(file, " %c", texto);
if (file == NULL) {
printf("Arquivo nao pode ser aberto\n");
return 0;
}
a=0;
do{
printf("%c", texto[a]);
a++;
} while (a<1000);
}
You forgot to put one
'\0'
after the last character copied from . txt; depending on the values previously in the stack, this can cause thestrlen(texto)
issues a protection breach (GPF, Segfault, etc.)– Wtrmute
Thank you, I added in the reply.
– Lucas Trigueiro
Thank you, that’s exactly what I needed.
– Neyelson Alves