miércoles, 2 de noviembre de 2011

I was trying to make a FIFO simulation, but it does not work, although i think this code is more adapted for three frames.
Well this code is in C, and it's just the part of the main, because the other are FIFO functions.
This writes the numbers, but sometimes it writes the same number two times.
So, i know this code is bad. I just wanted to try. Here is the code:



    for( i = 0; i < TAMANIO; i++ ){
        for( j = 0; j < 3; j++ ){
            b[ j ] = a[ j ];

        }
           
            agregar( &ptrCabeza, &ptrTalon, a[ i ] );

            if( b[ i ] != a[ i ] ){
                retirar( &ptrCabeza, &ptrTalon );
               
            }
                if( b[ i ] == a[ i + 1 ] ){
                    retirar( &ptrCabeza, &ptrTalon );
                    agregar( &ptrCabeza, &ptrTalon, a[ i + 1 ] );
                }
                else{
                    if( b[ i ] == a[ i + 2 ] ){
                        retirar( &ptrCabeza, &ptrTalon );
                        agregar( &ptrCabeza, &ptrTalon, a[ i + 2 ] );
                    }
                }
               
           
        imprimeCola( ptrCabeza );



 


And this code can be a simulation how to copy some file:

#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

int main( int argc, char *argv[] );

#define TAM_BUF 4096
#define MODO_SALIDA 700

int main( int argc, char *argv[] )
{
    int ent_da, sal_da, leer_cuenta, escribir_cuenta;
    char bufer[ TAM_BUF ];

    if( argc != 3 ) exit( 1 );

    ent_da = open( argv[ 1 ], O_RDONLY );
    if( ent_da < 0 )
    exit( 2 );
    sal_da = open( argv[ 2 ], MODO_SALIDA );
    if( sal_da < 0 )
    exit( 3 );

    while( 1 ){

        leer_cuenta = read( ent_da, bufer, TAM_BUF );
        if( leer_cuenta <= 0 )
            break;
            escribir_cuenta = write( sal_da, bufer, leer_cuenta );
        if( escribir_cuenta <= 0 )
        break;
    }

    close( ent_da );
    close( sal_da );
    if( leer_cuenta == 0 )
        exit( 0 );
    else
        exit( 5 );
}
 

No hay comentarios:

Publicar un comentario