Brutkey

mir :neobot_box_dog_ears:
@mir@ice.ch3.st

hm my program executes fine but then segfaults


mir :neobot_box_dog_ears:
@mir@ice.ch3.st

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 
#include 

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;
}

imported green :rainforest_frog: (made in russia)
@green@ice.ch3.st

@mir int i = 0; i <= 2; i++ this actually iterates 3 times. it segfaults because it tries to read the 3rd element of the fnames array

mir :neobot_box_dog_ears:
@mir@ice.ch3.st

@green ope good catch

mir :neobot_box_dog_ears:
@mir@ice.ch3.st
no alt

@green now, what's with these \377 and \375 (broken characters, they render even worse in a normal terminal)

imported green :rainforest_frog: (made in russia)
@green@ice.ch3.st
green voice

@mir here you go. i hope my voice is cute neocat_floof_aww