Initial commit: add cat and yes
This commit is contained in:
commit
0c5f04cf56
|
@ -0,0 +1 @@
|
|||
#+TITLE: GRU coreutils
|
|
@ -0,0 +1,5 @@
|
|||
*
|
||||
!.gitignore
|
||||
!cat.c
|
||||
!yes.c
|
||||
!Makefile
|
|
@ -0,0 +1,12 @@
|
|||
CC = gcc
|
||||
CFLAGS= -Wall -Wextra
|
||||
LFLAGS=
|
||||
|
||||
all: cat yes
|
||||
|
||||
main: $(OBJFILES)
|
||||
$(CC) cat.c -o cat
|
||||
$(CC) yes.c -o yes
|
||||
|
||||
test: main
|
||||
./cat ../tests/test.txt
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
char ch;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
FILE *file = fopen(argv[i], "r");
|
||||
if (file == NULL ) {
|
||||
printf("Cannot find file: %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((ch = fgetc(file)) != EOF)
|
||||
{
|
||||
printf("%c", ch);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *output = "y";
|
||||
if (argc >= 1) {
|
||||
while (1) {
|
||||
for (int i = 1; i < argc; i++)
|
||||
printf("%s ", argv[i]);
|
||||
printf("\n");
|
||||
}
|
||||
} else {
|
||||
while (1) {
|
||||
printf("%s\n", output);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
Test
|
||||
Test
|
||||
123
|
Loading…
Reference in New Issue