Compare commits
2
Commits
71510881f3
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fe4bd42cf | ||
|
|
2958364b07 |
@@ -2,10 +2,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
int linenum;
|
||||
|
||||
int getword(FILE *, char *, int);
|
||||
void doubleword(char *, FILE *);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
@@ -27,6 +29,7 @@ int main(int argc, char *argv[]) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// getword reads a word from fp into buf, returning true if it was able to do so.
|
||||
int getword(FILE *fp, char *buf, int size) {
|
||||
int c;
|
||||
c = getc(fp);
|
||||
@@ -50,3 +53,20 @@ int getword(FILE *fp, char *buf, int size) {
|
||||
ungetc(c, fp);
|
||||
return buf[0] != '\0';
|
||||
}
|
||||
|
||||
void doubleword(char *name, FILE *fp) {
|
||||
char prev[128], word[128];
|
||||
|
||||
linenum = 1;
|
||||
prev[0] = '\0';
|
||||
while (getword(fp, word, sizeof word)) {
|
||||
if (isalpha(word[0]) && strcmp(prev, word) == 0)
|
||||
// word is a duplicate
|
||||
{
|
||||
if (name)
|
||||
printf("%s:", name);
|
||||
printf("%d: %s\n", linenum, word);
|
||||
}
|
||||
strcpy(prev, word);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
hey there
|
||||
it's been a very very long
|
||||
time since
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
extern int Arith_max(int x, int y);
|
||||
extern int Arith_min(int x, int y);
|
||||
extern int Arith_div(int x, int y);
|
||||
extern int Arith_mod(int x, int y);
|
||||
extern int Arith_ceiling(int x, int y);
|
||||
extern int Arith_floor (int x, int y);
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#include "arith.h"
|
||||
|
||||
int Arith_max(int x, int y) {
|
||||
return x > y ? x : y;
|
||||
}
|
||||
|
||||
int Arith_min(int x, int y) {
|
||||
return x > y ? y : x;
|
||||
}
|
||||
|
||||
int Arith_div(int x, int y) {
|
||||
if (/* division truncates toward 0 */ -13/5 == -2
|
||||
&& /* x and y have different signs */ (x < 0) != (y < 0)
|
||||
&& x%y != 0)
|
||||
return x/y - 1;
|
||||
else
|
||||
return x/y;
|
||||
}
|
||||
|
||||
int Arith_mod(int x, int y) {
|
||||
return x - y*Arith_div(x, y);
|
||||
}
|
||||
|
||||
int Arith_floor(int x, int y) {
|
||||
return Arith_div(x, y);
|
||||
}
|
||||
|
||||
int Arith_ceiling(int x, int y) {
|
||||
return Arith_div(x, y) + (x%y != 0);
|
||||
}
|
||||
Reference in New Issue
Block a user