diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-11 22:35:10 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-11 22:35:10 +0200 |
commit | de1d7cd15a6792deca7b1d5f2ee1bf84d9751980 (patch) | |
tree | 8c11d8c5e0908896169378066eb7aad21029098a | |
parent | f1f51e8cf736a3ef0ceb532116bb3c200b37f871 (diff) | |
download | re-name-de1d7cd15a6792deca7b1d5f2ee1bf84d9751980.tar.gz |
Read new file names from standard in first
Theoretically, this might be more efficient.
-rw-r--r-- | name.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -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"); |