1
0

be kind, save a byte

This commit is contained in:
dtb 2023-08-11 17:39:29 -04:00
parent a490eb13ae
commit a6f6736d12
2 changed files with 6 additions and 12 deletions

View File

@ -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

View File

@ -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;