From de1d7cd15a6792deca7b1d5f2ee1bf84d9751980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 11 Jul 2021 22:35:10 +0200 Subject: Read new file names from standard in first Theoretically, this might be more efficient. --- name.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/name.c b/name.c index 57a467d..e74cd31 100644 --- a/name.c +++ b/name.c @@ -63,18 +63,18 @@ usage: fprintf(stderr, "usage: %s [-x]\n", name); if(!(fp = fopen(file, "r"))) err(1, "fopen"); - /* Read original file names. */ - for(i = 0; i < MAXFILES && fgets(tmp, MAXLINE, fp); i++){ - tmp[strcspn(tmp, "\n")] = 0; - strcpy(froms[i], tmp); - } - /* Read new file names. */ for(j = 0; j < MAXFILES && fgets(tmp, MAXLINE, stdin); j++){ tmp[strcspn(tmp, "\n")] = 0; strcpy(tos[j], tmp); } + /* Read original file names. */ + for(i = 0; i < MAXFILES && fgets(tmp, MAXLINE, fp); i++){ + tmp[strcspn(tmp, "\n")] = 0; + strcpy(froms[i], tmp); + } + if(i != j){ fprintf(stderr, "%s: too %s lines\n", name, j > i ? "many" : "few"); -- cgit v1.2.3