.


:




:

































 

 

 

 


"UNIX"

 

: . .-31

..

 

 

: ..

 

2

 

2014

:

 

 


1. 1.................................................................................................................................................. 3

2. 2.................................................................................................................................................. 6

:.................................................................................................................................... 9



1

C++ g++ UNIX, :

- list : , , ;

- list ;

- list1 list, ʔ.

.

 

Unix

:

 

int open (const char* path, int accesmode, int permission) - fcntl.h, path - , permission 0.

: _RDONLY - , _WRONLY - , O_RDWR .

, O_CREAT - , . -1 .

 

int create (const char* path, int accesmode) - .

 

long read (int fdesc, void* buf, int size) - .

unistd.h, fdesc - , buf - , , size - , . .

 

long write (int fdesc, const void* buf, int size) - .

- unistd.h, read. , .

 

long lseek (int fdesc, long pos, int whence) - - . - unistd.h, pos - , . whence : SEEK_CUR - ; SEEK_SET - ; SEEK_END - . .

 

#include <stdio.h>

#include <unistd.h>

#include <sys/types.h>

#include <fcntl.h>

#include <string.h>

#define N 5

 

struct TComp

{

char* name[15];

int count;

float price;

} Comp, fcomp;

 

char* fname="list";

 

void make_file()

{

int f=open(fname, O_WRONLY|O_CREAT,0);

if (f==-1)

{

perror(" ");

exit (1);

}

for(int i=0; i<N; i++)

{

puts (" : ");

scanf("%s",&Comp.name);

puts(" : ");

scanf("%i %f", &Comp.count, &Comp.price);

write(f, &Comp, sizeof(Comp));

printf("name=%s; count=%i; price=%f;\n", Comp.name, Comp.count, Comp.price);

}

close(f);

}

 

void max_price()

{

 

fcomp.price = 0;

int f1 = open(fname, O_RDONLY, 0);

if (f1==-1)

{

perror(" ");

exit (1);

}

while (read(f1, &Comp, sizeof(Comp)))

{

if (Comp.price > fcomp.price)

{

fcomp.name = Comp.name;

fcomp.count = Comp.count;

fcomp.price = Comp.price;

}

printf("%s price is %f.\n", Comp.name, Comp.price);

}

printf("Computer %s has maximum price of %f", fcomp.name, fcomp.price);

close(f1);

}

 

 

void prosmotr()

{

int f2=open(fname, O_RDONLY,0);

if (f2==-1)

{

perror(" ");

exit (1);

}

while (read(f2, &Comp, sizeof(Comp)))

{

printf("name=%s; count=%i; price=%f;\n", Comp.name, Comp.count, Comp.price);

}

close(f2);

}

 

void main()

{

int option;

 

puts(" : ");

puts("1- ; 2- . ; 3- :");

scanf("%i", &option);

switch(option)

{

case 1: make_file(); break;

case 2: max_price(); break;

case 3: prosmotr(); break;

}

}

 


2

. :

- .

- , . .

 

.

. , , . : AF_UNIX ( - Unix) AF_INET ( - - ).

, . - , , . - , . - , , . , , , , .

, Unix- . - TCP, -UDP.



<== | ==>
 |
:


: 2016-11-12; !; : 248 |


:

:

- - , .
==> ...

1691 - | 1644 -


© 2015-2024 lektsii.org - -

: 0.016 .