Написать(дополнить) программу на Си под Linux
500 руб. за проект
Изменить уже существующий код так, чтобы каждый каталог обрабатывался отдельным потоком, а передача результата осуществлялась через pipe. Си под LINUX.
Вот код:
#include <stdio.h>
#include <dirent.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
struct search_result
{
char name[PATH_MAX];
size_t digits;
};
static size_t count_digit(const char *str)
{
size_t cnt = 0;
for (; *str; str++) {
cnt += isdigit(*str);
}
return cnt;
}
static void search_file(struct search_result *result)
{
DIR *cwd;
struct dirent *entry;
char cwd_path[PATH_MAX];
size_t tmp;
if (!getcwd(cwd_path, PATH_MAX)) {
perror("getcwd error");
return;
}
if (cwd = opendir(cwd_path)) {
while ((entry = readdir(cwd))) {
switch (entry->d_type)
{
case DT_DIR:
if (*(entry->d_name) == '.') {
continue;
}
chdir(entry->d_name);
search_file(result);
chdir("..");
break;
default:
tmp = count_digit(entry->d_name);
if (tmp > 0) {
if (result->digits == 0 || tmp < result->digits) {
strncpy(result->name, entry->d_name, PATH_MAX);
result->digits = tmp;
}
}
break;
}
}
closedir(cwd);
}
else {
perror("opendir error");
}
}
int main(void)
{
struct search_result result = {0};
search_file(&result);
puts(result.name);
return 0;
}
Вот код:
#include <stdio.h>
#include <dirent.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
struct search_result
{
char name[PATH_MAX];
size_t digits;
};
static size_t count_digit(const char *str)
{
size_t cnt = 0;
for (; *str; str++) {
cnt += isdigit(*str);
}
return cnt;
}
static void search_file(struct search_result *result)
{
DIR *cwd;
struct dirent *entry;
char cwd_path[PATH_MAX];
size_t tmp;
if (!getcwd(cwd_path, PATH_MAX)) {
perror("getcwd error");
return;
}
if (cwd = opendir(cwd_path)) {
while ((entry = readdir(cwd))) {
switch (entry->d_type)
{
case DT_DIR:
if (*(entry->d_name) == '.') {
continue;
}
chdir(entry->d_name);
search_file(result);
chdir("..");
break;
default:
tmp = count_digit(entry->d_name);
if (tmp > 0) {
if (result->digits == 0 || tmp < result->digits) {
strncpy(result->name, entry->d_name, PATH_MAX);
result->digits = tmp;
}
}
break;
}
}
closedir(cwd);
}
else {
perror("opendir error");
}
}
int main(void)
{
struct search_result result = {0};
search_file(&result);
puts(result.name);
return 0;
}
В заказе есть исполнитель
При переводе заказа из архивного в актуальный, текущий исполнитель будет снят с задачи.
Выберите тип сделки
С безопасной сделкой вы всегда сможете вернуть средства, если что-то пойдет не так. С простой сделкой вы самостоятельно договариваетесь с исполнителем об оплате и берете на себя решение конфликтов.