added pipe example
This commit is contained in:
		
							parent
							
								
									c8bc30878e
								
							
						
					
					
						commit
						a99dd50c31
					
				|  | @ -0,0 +1,32 @@ | ||||||
|  | #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); | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue