You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
694 B
28 lines
694 B
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include<fcntl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
void main(void) {
|
|
char saludo[] = "Saludos peña!!!\n";
|
|
char buffer[10];
|
|
int fd, bytesleidos;
|
|
fd = open("texto.txt",1); // abrimos para escritura
|
|
if (fd==-1) {
|
|
printf("Algo salió mal\n");
|
|
exit (-1);
|
|
}
|
|
printf("Escribo el saludo en el fichero...");
|
|
write(fd,saludo, strlen(saludo));
|
|
close(fd);
|
|
fd=open("texto.txt",0); // abrimos para lectura
|
|
printf("Contenido del Fichero: \n");
|
|
bytesleidos = read(fd,buffer,1);
|
|
while (bytesleidos!=0) {
|
|
printf("%s", buffer);
|
|
bytesleidos = read(fd,buffer,1);
|
|
}
|
|
close (fd);
|
|
} |