Hola Gente:
Me dieron esta consigna:
Crear un programa en C que tenga un menú, de dos opciones. crear archivo y leer archivo. Lo resolví así:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int textocrea();
int textolee();
int main() {
//char text [1000];
//char entrada [1000];
int opcion = 0;
printf("Seleccione la opcion:\n");
printf("Opcion 1) crear texto en archivo\nOpcion 2) Leer archivo\n");
scanf("%i", &opcion);
switch(opcion){
case 1:
textocrea();
break;
case 2://funciona!!!
textolee();
break;
default:
printf("Selecciono una opcion no existente\n");
break;
}
return 0;
}
textocrea()
{
FILE *vfile;
char caracter[1000];
vfile = fopen("d:/texto.txt", "w");
if(vfile==NULL){
printf("Error al crear archivo\n");
}
printf("Ingrese el texto\n");
scanf( " %[^\n]",&caracter );
fputs(caracter, vfile);
fclose(vfile);
return 0;
}
textolee()
{
FILE *vfile;
char caracter [1000];
vfile = fopen("d:/texto.txt", "r");
if(vfile==NULL){
printf("Error al crear archivo\n");
}
while(!feof(vfile)){
fread(&caracter, sizeof(caracter), 1, vfile);
printf("%s", caracter);
}
fclose(vfile);
return 0;
}
Sin embargo me dice mi profe que por qué no definí las funciones como void. Probé y no funcionan con void. Tampoco funciona el gets en vez del scanf. Alguien sabe por qué pasa esto? Cómo es lo de las funciones void?
Desde ya gracias Chicos!!!





Autor


En línea




Igual te recomiendo conseguir algun libro, asi vas a tener una buena base y poder resolver casi todos tus dudas.

Que hace el minicódigo? 
