Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Gr1nD3r en 16 Julio 2010, 10:49 am



Título: fprintf y fputs
Publicado por: Gr1nD3r en 16 Julio 2010, 10:49 am
Hola a todos. Mi duda es la siguiente:
Que diferencia hay entre fputs y fprintf??


Título: Re: fprintf y fputs
Publicado por: Littlehorse en 16 Julio 2010, 11:02 am
delvier1993, bienvenido/a al foro!. Para este tipo de dudas, procura antes utilizar el buscador del foro o bien utilizar Google.

fprintf (http://www.cplusplus.com/reference/clibrary/cstdio/fprintf/):

Citar
Write formatted output to stream
Writes to the specified stream a sequence of data formatted as the format argument specifies. After the format parameter, the function expects at least as many additional arguments as specified in format.


Código
  1. /* fprintf example */
  2. #include <stdio.h>
  3.  
  4. int main ()
  5. {
  6.   FILE * pFile;
  7.   int n;
  8.   char name [100];
  9.  
  10.   pFile = fopen ("myfile.txt","w");
  11.   for (n=0 ; n<3 ; n++)
  12.   {
  13.     puts ("please, enter a name: ");
  14.     gets (name);
  15.     fprintf (pFile, "Name %d [%-10.10s]\n",n,name);
  16.   }
  17.   fclose (pFile);
  18.  
  19.   return 0;
  20. }





fputs (http://www.cplusplus.com/reference/clibrary/cstdio/fputs/):

Citar
Write string to stream
Writes the string pointed by str to the stream.
The function begins copying from the address specified (str) until it reaches the terminating null character ('\0'). This final null-character is not copied to the stream.

Código
  1. /* fputs example */
  2. #include <stdio.h>
  3.  
  4. int main ()
  5. {
  6.   FILE * pFile;
  7.   char sentence [256];
  8.  
  9.   printf ("Enter sentence to append: ");
  10.   fgets (sentence,255,stdin);
  11.   pFile = fopen ("mylog.txt","a");
  12.   fputs (sentence,pFile);
  13.   fclose (pFile);
  14.   return 0;
  15. }


Saludos!


Título: Re: fprintf y fputs
Publicado por: nicolas_cof en 16 Julio 2010, 19:57 pm
delvier1993, por las dudas no le hagas al ingles :P, te dejo unos links en español...

http://c.conclase.net/librerias/?ansifun=fputs
http://c.conclase.net/librerias/?ansifun=fprintf

Pero como bien menciono Littlehorse, son preguntas que se contestan buscando en el foro o en Google...

Utiliza el buscador de la Wiki, que es el que esta andando bien por el momento: http://wiki.elhacker.net/

Salu10.