=====MAIN=====
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "newLines.h"
int main(int argc, char *argv[]){
FILE *fd;
int i;
fd = fopen(argv[argc-1],"r");
if(fd==NULL || argc<2){
printf("FILE NOT FOUND");
exit(1);
}
for(i=1;i<argc;i++){
if(strcmp(argv[i],"w")==0) { printf("%d\n",newLines(fd));}
}
printf("OK\n");
exit(0);
}
=====NEWLINES=====
#include <stdio.h>
#include <stdlib.h>
#include "newLines.h"
int newLines(FILE *fd){
int count;
while(1){
if(fgetc(fd)=='\n')
count++;
if(feof(fd)) break;
}
return count;
}
=====MAKEFILE=====
CC=gcc
CFLAGS=-c -Wall -Wextra
all : wc
wc : main.o newLines.o
$(CC) main.o newLines.o -o wc
main.o : main.c
$(CC) $(CFLAGS) main.c
newLines.o : newLines.c
$(CC) $(CFLAGS) newLines.c