Lol C to write a string manipulation algorithm?@Jehannum
Code:#include <stdio.h> #include <string.h> int diffchars(char *a, char *b, int wordlen); int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr,"usage: %s <wordlist.txt> <word>\n",argv[0]); return 0; } FILE *f = fopen(argv[1],"r"); if (f == NULL) { fprintf(stderr,"Could not open wordlist file \"%s\"\n",argv[2]); return 0; } int wordlen = strlen(argv[2]); char line[50]; while(!feof(f)) { if (fgets(line,50,f) == NULL) break; line[strcspn(line, "\n")] = 0; // remove null terminator if (strlen(line) != wordlen) continue; if (diffchars(argv[2],line,wordlen) == 1) { fprintf(stdout,"%s\n",line); } } fclose(f); return 1; } int diffchars(char *a, char *b, int wordlen) { int diffs = 0; while(wordlen--) if (*a++ != *b++) diffs++; return diffs; }
hmm, lets try Tom Petty...
Code:gmarsh@torrentbox:~/c$ ./wordfind scrabble.txt petty jetty netty patty peaty pesty petti petto potty putty gmarsh@torrentbox:~/c$
Tom Potty it is!
What's wrong with a unix command line application for this job?Lol C to write a string manipulation algorithm?
Is C the only language you know?
What, he should have done it with a bash script?Lol C to write a string manipulation algorithm?
Is C the only language you know?
If you know c, you should write in cLol C to write a string manipulation algorithm?
Is C the only language you know?
for something CPU instensive, sure. for a something basic, hell no.If you know c, you should write in c
lolcode would have been betterWhat, he should have done it with a bash script?