Hello, i am trying to use a variable of a file on a function away from the main function, and writing something, but the program crashes without typing anything on the file, how could I write something without initializing a variable on the funcition?
I have tried using pointer to the variable and I`m prettty sure that there is the failure, this is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void cambio(FILE *a);
int main(){
FILE *archivo;
char name[20],lec;
std::cout<<"Type the name of the file: ";
std::cin>>name;
archivo=fopen(name,"w+");
cambio(archivo);
while(feof(archivo)==0){
lec=fgetc(archivo);
std::cout<<lec;
}
}
void cambio(FILE *a){
fputs("Añadido",a);
}