syntax error c ++

-2

hi friends I am new here I want you to help me in this program I am using a textbox. it turns out that the information I want to save it in a text file but that the user names the text file I think the way I keep it is bad

void admpacientes()
{

char nfichero[50];
gotoxy(4,5);printf("ADMINISTRACION DEL PACIENTE");

gotoxy(1,8);printf("NOMBRE:");
textbox nombre(8,8,20,19);
nombre.Mostrar();
nombre.Capturar();

gotoxy(1,11);printf("APELLIDO:");
textbox apellido(10,11,20,19);
apellido.Mostrar();
apellido.Capturar();

gotoxy(35,11);printf("EDAD:");
textbox edad(40,11,5,5);
edad.Mostrar();
edad.Capturar();

gotoxy(1,15);printf("DIRECCION:");
textbox direccion(11,15,35,30);
direccion.Mostrar();
direccion.Capturar();

gotoxy(50,15);printf("CELULAR:");
textbox cel(58,15,15,13);
cel.Mostrar();
cel.Capturar();

gotoxy(1,19);printf("REGION:");
textbox rg(10,19,15,13);
rg.Mostrar();
rg.Capturar();

gotoxy(35,19);printf("PAIS:");
textbox pais(40,19,15,13);
pais.Mostrar();
pais.Capturar();

gotoxy(1,22);printf("INGRESE EL NOMBRE DEL ARCHIVO DONDE DESEA GUARDAR LA INFORMACION DEL PACIENTE: ");
    scanf("%s",&nfichero);


 FILE *archivo;

archivo=fopen("nfichero.txt","w"); //para escritura

fprintf(archivo,"%s\n%s\n,%d\n,%s\n,%d\n,%s\n,%s\n",nombre.Texto(),apellido.Texto(),edad.Texto(),direccion.Texto(),cel.Texto(),rg.Texto(),pais.Texto());

fclose(archivo);

getch();
system("CLS");
}//fin depantalla administrador de pacientes
    
asked by Ariel torres 06.12.2018 в 06:53
source

1 answer

2
printf("Ingrese el nombre del archivo con la extension (.txt): ");
scanf("%s",&nfichero); //Aqui el usuario ingresa ejemplo.txt
FILE *archivo = fopen(nfichero,"w"); //Aqui se le da el nombre almacenado en nfichero

What you are doing is giving it the name "nfichero.txt" directly, when what you want to do is give it the name stored in nfichero . That's why you should send it as a parameter when using the function FILE * fopen (const char *filename, const char *opentype) .

    
answered by 06.12.2018 в 09:29