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.
35 lines
764 B
35 lines
764 B
12 months ago
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/wait.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...\n");
|
||
|
write(fd, saludo, strlen(saludo));
|
||
|
close(fd);
|
||
|
|
||
|
fd = open("texto.txt", 0); // abrimos para lectura
|
||
|
printf("Contenido del Fichero: ");
|
||
|
|
||
|
bytesleidos = read(fd, buffer, 1);
|
||
|
while (bytesleidos != 0)
|
||
|
{
|
||
|
printf("%s", buffer);
|
||
|
bytesleidos = read(fd, buffer, 1);
|
||
|
}
|
||
|
close(fd);
|
||
|
}
|