Aquí, vamos a aprender acerca de los fputs () la función de cabecera stdio.h biblioteca en lenguaje C con su sintaxis, ejemplo .
fputs () en C
Prototipo:
int fputs(const char *string,FILE *filename);
Parámetros:
const char *string,FILE *filename
Return tipo: int
Uso de la función:
En el manejo de archivos, a través de la función fputs () tomamos la cadena del usuario y almacenarlo para el flujo de entrada y se incrementa el indicador de puntero de archivo para aceptar la próxima entrada de cadena. El prototipo de la función fputs () es: int fputs (const char cadena *, * ARCHIVO nombre de fichero);
Devuelve el valor negativo en el éxito y return EOF para el fracaso. Aquí cadena es el conjunto de caracteres y el nombre de archivo es el nombre de la secuencia de archivo.
fputs () ejemplo en C
#include <stdio.h>
#include <stdlib.h>
int main(){
//Initialize the file pointer
FILE *f;
//Take a array of characters
char ch[100];
//Create the file for write operation
f=fopen("includehelp.txt","w");
printf("Enter five stringsn");
for(int i=0;i<4;i++){
//take the strings from the users
scanf("%[^n]",&ch);
//write back to the file
fputs(ch,f);
//every time take a new line for the new entry string
//except for last entry.Otherwise print the last line twice
fputs("n",f);
//clear the stdin stream buffer
fflush(stdin);
}
//take the strings from the users
scanf("%[^n]",&ch);
fputs(ch,f);
//close the file after write operation is over
fclose(f);
//open a file
f=fopen("includehelp.txt","r");
printf("n...............print the strings..............n");
while(!feof(f)){
//takes the first 100 character in the character array
fgets(ch,100,f);
//and print the strings
printf("%s",ch);
}
//close the file
fclose(f);
return 0;
}
salida