Files
ioccc/1994/schnitzi
Cody Boone Ferguson ffb639d42d Undo buffer size increase in 1994/schnitzi
As part of redefining INABIAF the entry now has an equivalent
functionality with the generated output. The bugs.md file still has
hints on how to get this to use fgets() (for why this is helpful see
that file). As a starting point I have the original buffer size increase
in schnitzi.alt.c as it would be useful to see how it works and to maybe
get the entry to use fgets(). Unfortunately keeping it using gets() is a
potential problem but changing it to fgets() is also a potential problem
(this goes for all of the entries that use or used gets()). This entry
however still uses gets(). The change is the smaller buffer size which
means that the entry can not handle big files.

The Makefile and README.md now refer to the small buffer size.
2023-04-07 10:23:20 -07:00
..

Best Layout:

Mark Schnitzius ISX Corporation 1165 Northchase Pkwy, Suite 120 Marietta, GA 30067 USA

To build:

make all

To run:

./schnitzi < textfile

Try:

./schnitzi < /etc/motd
./schnitzi < /etc/passwd

NOTE: the buffer size is very small at 100. It's easy to fix the buffer size but it is not as easy to change it to fgets(). Cody Boone Ferguson gives some hints in the bugs.md file on how this entry works which might be useful in order to get this to use fgets() which would prevent a warning at linking or runtime. The file schnitzi.alt.c has this to get anyone started, should they wish to tackle it (Cody will in time). The problem with changing the buffer size is that even when it works the generated output (see judges' comments below) will not be 100% correct duplication of the program.

Alternate code:

To build the alternative code try:

make alt

Use schnitzi.alt as you would schnitzi.

Judges' comments:

Try:

./schnitzi < schnitzi.c

Compare the output of the program with its source. Sure the output is different, but there is more than meets the diff's eye. Can you find out why?

Author's comments:

SPOILER:

This is a program which takes any text file as input and 'flips' the input file along a diagonal running from the top left corner down to the bottom right. In other words, the first row in the file ends up written down the first column of the result, the second row is written down the second column, etc. The program is run by redirecting a file into the executable on the command line; for instance, for the included 'info' file, the program would be run as follows:

	schnitzi < info

The program generates interesting results when its source file is used as input:

	schnitzi < schnitzi.c

The result of this command is a program which does the exact same thing -- in other words, both the program and the "flipped" version of itself work identically (you'll need to redirect the output of the above command into a separate file and compile it). You might notice some differences in the flipped version, though. First off, a secret message becomes visible that was not visible in the original program. Also, much of the code shows up in different places in the flipped program than it appeared in the first program. My first version of this program was perfectly symmetrical along the diagonal, but later found out there were interesting ways to break the symmetry. The best way to see this is to load both the original and flipped versions of the program into an editor and switch back and forth between them rapidly.

C tokens longer than a character (such as "main") proved difficult to use in both the original and flipped versions (after flipping, they show up as a string of single letters on successive lines). However, I found that it was possible to get around this through a few well-placed comments. An earlier version of this program used nearly every single-character token in the "shared" area; however, it proved to be too large for contest guidelines (although the code itself is only about 300 characters, the extra whitespace needed to pad it put it over the limit -- it nearly filled a 79 by 79 area, adding up to over 4000 total characters). I will provide this other version to anyone interested -- contact me by email at schnitzi@east.isx.com.

This file is Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved. You are free to share and adapt this file under the terms of this license:

Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)

For more information, see: https://creativecommons.org/licenses/by-sa/4.0/