Fich: Abrir y mostrar fichero entre 3 opciones

abrir y mostrar fichero 3 opciones.html
#include <stdio.h>
#include <string.h>

int main(){
	int opcion;
	char nombre[200];
	char texto[1000];
	
	FILE *f;
	printf("Los archivos que tenemos son:\n");
	printf("\n1.Refran \n2.Tiempo \n3.Libros\n\n");
	printf("Cual quiere abrir: ");
	scanf("%d",&opcion);
	fflush(stdin);
	
	switch(opcion){
		case 1: strcpy(nombre,"refran.txt");
		break;
		case 2: strcpy(nombre,"tiempo.txt");
		break;
		case 3: strcpy(nombre,"libros.txt");
		break;
		default: printf("Opcion no valida.\n");
		break;
	}
	
	f = fopen(nombre, "r");
	if(f==NULL){
		printf("No se ha podido abrir el archivo\n");
	}
	else{
		while(! feof(f)){
			fgets(texto,1000,f);
			printf("%s", texto);
		}
	}
	fclose(f);
	
	system("pause");
	return 0;
}

No hay comentarios:

Publicar un comentario