commit 843fbbf9ac42584b8827d17c704b3b89fe687d53
parent 30aa381af35bf3fae4c2965e02d7c107fca6b7dd
Author: Tyler Clark <tyler.clark@foxide.xyz>
Date: Sun, 9 Feb 2025 21:42:27 -0500
first commit
Diffstat:
D | head.c | | | 87 | ------------------------------------------------------------------------------- |
1 file changed, 0 insertions(+), 87 deletions(-)
diff --git a/head.c b/head.c
@@ -1,87 +0,0 @@
-/*
- * ARGUMENTS
- * =========
- * -c, --bytes: prints specified number of bytes
- * FINISHED: -n, --lines: Prints specified number of lines
- * =========
- * FINISHED: if there are multiple files specified ==> foo <== will be printed before
- * the lines in each file, where foo is the name of the file.
- */
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-
-int main(int argc, char *argv[]) {
- FILE *fp;
- char ch;
- int lines = 10; // Default number of lines, can be chaged at runtime with -n arg
- int i = 0;
- int files = 1;
- int delimeter = 0;
-
- int argByte = strcmp(argv[1], "-c");
- if (argByte == 0) {
- printf("Some stuff would happen here\n");
- int bytes = strtol(argv[2], NULL, 10);
- printf("It would print %d bytes\n", bytes);
- files = 3;
- if (files == (argc - 1)) {
- fp = fopen(argv[files], "r");
- i = 0;
- while(((ch = fgetc(fp)) != EOF) && (i < bytes)) {
- printf("%c", ch);
- i++;
- }
- return 0;
- } else {
- fp = fopen(argv[files], "r");
- i = 0;
- while(((ch = fgetc(fp)) != EOF) && (i < bytes)) {
- printf("%c", ch);
- i++;
- }
- return 0;
- }
- }
-
- int argLine = strcmp(argv[1], "-n");
- if (argLine == 0) {
- lines = strtol(argv[2], NULL, 10);
- files = 3;
- }
-
- if (files == (argc - 1)) {
- fp = fopen(argv[files], "r");
- while((ch = fgetc(fp)) != EOF) {
- if (i >= lines) {
- fclose(fp);
- i = 0;
- break;
- } else if (ch == '\n') {
- printf("%c", ch);
- i++;
- } else {
- printf("%c", ch);
- }
- }
- return 0;
- }
- for (files = files; files < argc; files++) {
- fp = fopen(argv[files], "r");
- printf("==> %s <==\n", argv[files]);
- while((ch = fgetc(fp)) != EOF) {
- if (i >= lines) {
- fclose(fp);
- i = 0;
- break;
- } else if (ch == '\n') {
- printf("%c", ch);
- i++;
- } else {
- printf("%c", ch);
- }
- }
- fclose(fp);
- }
- return 0;
-}