<div dir="ltr">Hola Felician,<div class="gmail_extra"><br><div class="gmail_quote">2013/6/13 felician draghici <span dir="ltr"><<a href="mailto:felix1900toamna@yahoo.es" target="_blank">felix1900toamna@yahoo.es</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>Hola, alguien me puede echar una mano con la escritura de un fichero?</div>
<div>No logro entender porque no me escribe en el fichero comidas.plato y luego no saca nada del fichero y lo tengo que escribir de nuevo,como si no se almacena nada cuando se vuelve a ejecutar el programa.</div><div>Tengo una struct con todos los datos necesarios y la funcion para guardar el nombre de la comida, su precio, y referencia.</div>
<div>Seria para buscar el plato por su referencia y que te muestre el precio y el nombre de esta.<br></div><div>Gracias por tu tiempo, un saludo<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<br></div></div></div></blockquote><div><br></div><div style>Desafortunadamente, no corregiste los errores que cometiste en el código fuente que nos enviaste en un correo-e anterior. Intentaré indicar los errores en este código fuente.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
struct pedido{<br>         char telefono[50];//numero de telefono del cliente<br>         char calle[50];//nombre de calle del cliente<br>         char portal[50];<br>         char piso[50];<br>         float pedidos;//valor pedido<br>
         float total_pedidos;//valor total de los
 pedidos<br>         float precio;<br>         int referencia;<br>         char plato[50];   <br>       };<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">struct pedido comidas_precios(struct pedido comidas)<br></div></div></div></blockquote>
<div><br></div><div style>Según el comportamiento de esta función, este parámetro, 'comidas', no te sirve. Sugiero crear 'comidas' dentro de esta función, pero no como parámetro. En su lugar, indica 'void' para la lista de parámetros.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
{<br>    struct pedido {//estructura para lectura<br></div></div></div></blockquote><div><br></div><div style>Esto va a ser un error, porque has redefinido 'struct pedido'. Elige otro nombre para esta estructura, para que no haya un conflicto entre nombres de tipos de datos.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
         int ref;<br>         char comida[50];<br>         float prec;<br>       
 }lectura;   <br>       <br></div></div></div></blockquote><div><br></div><div style>[CORTE]</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif">
<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">         do<br>         {<br>            fread(&comidas,sizeof(struct pedido),1,fc);<br></div>
</div></div></blockquote><div><br></div><div style>Esto provoca un error lógico, porque estás indicando 'struct pedido' que definiste en esta función y no 'struct pedido' que definiste globalmente, que es el tipo de dato de 'comidas'. Por eso deberías usar nombres diferentes para los tipos de dato.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
            if(lectura.ref ==
 comidas.referencia)<br>            {                           <br>                 encontrado = 1; <br>                 printf("\nSi"); <br>                 break;                                          </div>
</div></div></blockquote><div><br></div><div style>En general, no sugiero usar 'break' al menos que no tengas otra forma de hacer lo que quieres.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><span style="font-family:arial;font-size:small"> </span></div>
</div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
            }<br>        
 }while(!feof(fc));<br>         <br></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif">
<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">         <br>         if(encontrado==1)<br>         {    <br>                fgets(comidas.plato,1,fc);<br>
</div></div></div></blockquote><div><br></div><div style>Esto no tiene sentido, porque ya leíste el registro encontrado y lo guardaste en 'comidas'. No necesitas invocar esta función, así que elimina esta sentencia.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
                printf("\nReferencia: %d",comidas.referencia);      <br>                printf("\nComida: %s",comidas.plato);<br>                printf("\nPrecio: %.2f",comidas.precio);<br>         }<br>
        
 else<br>         {<br>             comidas.referencia=lectura.ref;//<br>             printf("\n%d",comidas.referencia);//<br>             printf("\nNombre del plato: ");<br>             gets(comidas.plato);<br>
             printf("\nIntroduce el precio de %s: ",comidas.plato);<br>             scanf("%f",&comidas.precio);<br>             fflush(stdin);<br>            
 <br>             printf("\n%s",comidas.plato);<br>                        <br>         }<br>         fwrite(&comidas,sizeof(struct pedido),1,fc);<br></div></div></div></blockquote><div><br></div><div style>
Nuevamente, si no cambias el nombre de la estructura definida aquí en esta función, esta escritura al fichero no se realizará correctamente como quieres.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">        //fgets(comidas.plato,fc);<br>
     }<br>     <br>    fclose(fc);   <br>  getchar();<br>return comidas;    <br>}<br><br></div></div></div></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra" style>
Espero que esto aclare las dudas.</div><div class="gmail_extra"><br></div><div class="gmail_extra" style>Steven</div><div class="gmail_extra" style><br></div></div>