All pastes #365214 Raw Edit

basici/o systemcalls

public text v1 · immutable
#365214 ·published 2007-02-20 19:54 UTC
rendered paste body
 cat ex_1.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>

int main()
{
        int fd;
        int n;
        int array[100];
        int array_t[100];
        int temp = 0;
        int count100 = 0;
        int countMod = 0;
        int noOfIntegers = 0;
        int startingInteger = 0;
        int i = 0;

        fd = open("data_file.txt",O_RDWR);

        if (fd < 0)
        {
                printf("File not created creating a new file");
                fd = open("data_file.txt",O_RDWR|O_CREAT,0777);
                printf("File Not existing , creating \n");
                if (fd < 0)
                {
                        printf("Some error in creating the file \n");
                        exit(0);
                }

        }


        for (i = 0;i < 100 ;i++,startingInteger++)
        {
                array[i] = startingInteger;
        }
        for (i = 0;i<100;i++)
                        printf("%d",array[i]);

        printf("---\n");

        n = write(fd,array,100);

        close(fd);

        fd = open("data_file.txt",O_RDONLY);

        n = read(fd,array_t,100);

        for (i = 0;i<100;i++)
                        printf("%d",array_t[i]);



        close(fd);


        return 0;
}

output
------
0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899---
0123456789101112131415161718192021222324100000000-1075104004006-12080841601048575810000000000000000000000000000009569028095927881345126927-107510413695649651345126927-10751046163132617-10751044820-100713451269213451360419701701881200000000