String equality tester
_Bool strequals(char* a, char* b) { if (!a || !b) return 0; do {if (*a != *b) return 0; } while (*a++ && *b++); return 1; }
DZone Snippets > Minimiscience
11381 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
_Bool strequals(char* a, char* b) { if (!a || !b) return 0; do {if (*a != *b) return 0; } while (*a++ && *b++); return 1; }
void ungets(char* str, FILE* stream) { if (!str || !file) return -1; size_t len = strlen(str); for (int i=len-1; i>=0; i--) if (ungetc(str[i], stream) == EOF) return -1; return len; }
#!/usr/bin/perl -wl use strict; $_ = shift or die 'Invalid argument passed'; s/\s+//g; /^(\d+)[dD](\d+)([+-]\d+)?$/ or die 'Invalid argument passed'; my $sum = 0; $sum += 1 + int rand $2 for 1..$1; $sum += $3 if defined $3; print $sum;
#!/usr/bin/perl -wn use strict; s/\s//g; print chr hex $1 while /([[:xdigit:]]{2})/g; print "\n";
#!/usr/bin/perl -w use strict; my %exten; foreach (@ARGV) { /(\.[^.]+)$/ && $exten{$1}++ foreach glob "$_/*.*" } print "$_: $exten{$_}\n" foreach sort keys %exten;
#!/usr/bin/perl -wn use strict; s/\s//g; print chr oct "0b$1" while /([01]{8})/g; print "\n";
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char** argv) { int qty = (argc > 1) ? (int) strtol(argv[1], NULL, 10) : 100; if (qty < 3) qty = 100; unsigned int primes[qty]; primes[0] = 2U; primes[1] = 3U; printf("2\n3\n"); for (int i=2; i<qty; i++) { int j = primes[i-1]; iter: j += 2U; unsigned bound = (unsigned) sqrt((double) j); for (int k=1; k<i; k++) { if (primes[k] > bound) break; /*Not a viable shortcut for small quantities*/ if (!(j % primes[k])) goto iter; } primes[i] = j; printf("%u\n", j); } return 0; }
#!/usr/bin/perl -w use strict; use Socket; my $arg = shift; if ($arg =~ /^(\d+\.){3}\d+$/) { print scalar gethostbyaddr(inet_aton($arg), AF_INET), "\n" } else { printf "%vd\n", scalar gethostbyname $arg }
#!/usr/bin/perl -wni # para.pl use strict; /^\s+/ || /^$/ ? print : write; format ARGVOUT = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $_ .