Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- enum {size = 50 };
- //количество вхождений символа "с"
- int fcount(const char *path, char c)
- {
- int fd = open(path, O_RDONLY);
- if (fd < 0) return -1;
- //место под массив, куда считываем
- char a[size];
- //считываем по 50 элементов
- int n = 0, count = 0;
- while ((n = read (fd, a, size)) > 0)
- {
- int i = 0;
- for(; i < n; i++)
- {
- if (a[i] == c) count++;
- }
- }
- close(fd);
- return count;
- }
- //переименовать файл
- int rename1(char *from, char *to )
- {
- unlink( to ); /*удалитьфайлto */
- if( link( from, to ) < 0 ) /* связать */
- return (-1);
- unlink( from ); /* стереть старое имя */
- return 0; /* OK */
- }
- //вернуть размер файла
- off_t size_file (const char *path)
- {
- int fd = open(path, O_RDONLY);
- if (fd == -1 ) return -1;
- off_t s = lseek (fd, 0, SEEK_END);
- close(fd);
- return(s);
- }
- int main (void)
- {
- //int a = rename1 ("a.rtf", "b.rtf");
- off_t b = size_file ("b.rtf");
- long long l = b;
- printf("%ll\n", l);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement