heres the program btw. test.txt and txt2.txt are files with keysmashes and copypasta in the working directory. im just running gcc mircat.c and it spits out a a.out that's executable
/*
my first C program ever! gonna make a copy of `cat` with maybe extra features
idk
/* */
#include <stdio.h>
#include <string.h>
char* greeting = "bonjour";
char *fnames[] = {"test.txt","tst2.txt"};
int catfile (char* file){
FILE *stream ;
int beg ;
int end ;
stream = fopen(file, "r") ; // type `FILE *`
fseek(stream, 0, SEEK_SET);
beg = ftell (stream); // should always be 0
fseek(stream, 0, SEEK_END);
end = ftell (stream); //end of file
char contents[end] ;
for (int i = beg; i <= end ; i++) {
fseek(stream, i, SEEK_SET); // go to next position
contents[i] = fgetc (stream); // get char at said pos and assign it thusly
};
printf ("file %s starts at %ld and ends at %ld\nits contents follow:\n%s\n\n",
file, beg, end,
contents
);
};
int main (){
printf ("%s\n\n",
greeting);
for (int i = 0; i <= 2; i++) {
catfile (fnames[i]);
} ;
return 0;
}
Embed Notice
HTML Code
Corresponding Notice
- Embed this notice
new mir (mir@ice.ch3.st)'s status on Friday, 31-Jan-2025 17:08:52 JST new mir