C/C++の宿題片付けます 145代目
■ このスレッドは過去ログ倉庫に格納されています
0073デフォルトの名無しさん
2011/01/06(木) 05:13:33#include <stdio.h>
static int trim_lsR_path(char *path, size_t size)
{
int i;
for (i = 0; i < size; i++)
if (path[i] == ':')
break;
return path[i] == ':' && i >= 1 ? path[i] = '\0', 0 : -1;
}
int main(void)
{
static char path[BUFSIZ], buf[BUFSIZ];
FILE *fp;
if ((fp = fopen("ls-R", "r")) == NULL)
return 1;
if (fgets(path, sizeof(path), fp) == NULL)
goto err;
if (trim_lsR_path(path, sizeof(path)) < 0)
goto err;
while (fgets(buf, sizeof(buf), fp) != NULL)
if (!strcmp(buf, "\n")) {
if (fgets(path, sizeof(path), fp) == NULL)
goto err;
if (trim_lsR_path(path, sizeof(path)) < 0)
goto err;
} else
printf("%s/%s", path, buf);
return fclose(fp), 0;
err:
return fclose(fp), 1;
}
■ このスレッドは過去ログ倉庫に格納されています