Files
CS361-Computer-Systems-II/p1-sh/utils/cat.c
T

42 lines
598 B
C
Raw Normal View History

2026-05-31 14:34:00 -04:00
#include <stdio.h>
#include <stdlib.h>
static void usage (void) __attribute__ ((unused));
int
main (int argc, char *argv[])
{
if (argc < 2)
{
int c;
while ((c = getchar()) != EOF)
{
putchar(c);
}
return EXIT_SUCCESS;
}
FILE *fp = fopen(argv[1], "r");
if (fp == NULL)
{
return EXIT_FAILURE;
}
int c;
while ((c = fgetc(fp)) != EOF)
{
putchar(c);
}
fclose(fp);
return EXIT_SUCCESS;
}
static void
usage (void)
{
printf ("cat, print the contents of a file\n");
printf ("usage: cat FILE\n");
}