From a6f6736d1272085ed3f758decc0c0a4a3a10ab57 Mon Sep 17 00:00:00 2001 From: dtb Date: Fri, 11 Aug 2023 17:39:29 -0400 Subject: [PATCH] be kind, save a byte --- streq/Makefile | 12 ++++-------- streq/streq.c | 6 ++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/streq/Makefile b/streq/Makefile index 9725de1..1d7f442 100644 --- a/streq/Makefile +++ b/streq/Makefile @@ -1,11 +1,7 @@ -all: streq +streq: streq.c + $(CC) -g -o streq streq.c clean: - rm -r streq + rm -f streq -sane: streq - -streq: streq.c - $(CC) -o streq streq.c - -.PHONY: all clean sane +.PHONY: clean diff --git a/streq/streq.c b/streq/streq.c index 5787e6b..4d3e404 100644 --- a/streq/streq.c +++ b/streq/streq.c @@ -6,7 +6,6 @@ static char *program_name = "streq"; int main(int argc, char *argv[]){ int i; - int j; if(argc < 3){ fprintf(stderr, "Usage: %s [string] [string...]\n", @@ -14,10 +13,9 @@ int main(int argc, char *argv[]){ return EX_USAGE; } - /* i is the arg index, j is the char index */ - for(j = 0; argv[1][j] != '\0'; ++j) + for(; *argv[1] != '\0'; ++argv[1]) for(i = 2; i < argc; ++i) - if(argv[i-1][j] != argv[i][j]) + if(*argv[i-1] != *argv[i]++) return 1; return 0;