Fix segfault in 1993/schnitzi + update README.md

If no file was specified or could not be opened the program segfaulted.
This has been fixed.

Format fixes in README.md.
This commit is contained in:
Cody Boone Ferguson committed 2023-03-30 12:05:15 -07:00
1 parent 9e07c1ae91
commit a411e62815
2 files changed
+69 -55

No files matched your search

+67 -53
View File
@@ -9,22 +9,44 @@
make all
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this use `fgets()`
not `gets()` to make it safer. Thank you Cody for your assistance!
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to not
segfault when no file is specified or the file cannot be opened for reading. he
also made this use `fgets()` not `gets()` to make it safer. Thank you Cody for
your assistance!
### To run
### To run:
./schnitzi file
./schnitzi file
where:
where:
file a file containing some text
## Judges' comments
## Try:
After this program prints the contents of 'file', ask it
some questions related to the text.
./schnitzi schnitzi.info
# ask some questions suggested by the author, noted below
We also suggest you ask the program:
Who is Mark Schnitzus?
Notice how it still manages to answer the question despite there being an
intentional spelling error there.
Try feeding the program source to the program and ask both:
What is cat ?
What is cat?
## Judges' comments:
After this program prints the contents of 'file', ask it
some questions related to the text.
The author suggests the following questions when using schnitzi.info:
The author suggests the following questions when using schnitzi.info:
Who is Mark Schnitzius?
What exactly does this program do?
@@ -35,65 +57,57 @@ not `gets()` to make it safer. Thank you Cody for your assistance!
Is it true that Elvis is alive?
Do colorless green ideas sleep furiously?
We suggest you try using the body (minus the header and signature line)
of a Usenet article. You might want to try something from alt.flame. :-)
We suggest you try using the body (minus the header and signature line)
of a Usenet article. You might want to try something from alt.flame. :-)
If you have a ' in the question this entry may fail.
NOTE: If you have a ' in the question this entry may fail.
NOTE: This entry uses `gets()` so you might get a warning when compiling and
running this entry.
NOTE: The author may also be contacted at: marks@aldrin.ksc.nasa.gov.
NOTE: this entry will likely segfault if you do not provide it with a data
file.
## Author's comments:
NOTE: The author may also be contacted at: marks@aldrin.ksc.nasa.gov
I wanted to write a program that would read in a text file in
natural language (such as English) and answer questions about that
text file. I thought this might be a complicated task, and I was
right -- it took me over 800 bytes. Of course, it doesn't always
work, but that's AI for you.
## Author's comments
This program accepts the name of a text file as the first
parameter. For example, to run it on the supplied data file called
'info' you would type `./schnitzi info`. It echoes the file, then
gives you a prompt where you may type in questions about that text.
The more words you use which are actually present in the text file,
the better results you get. You'll need to hit `ctrl-c` to break out
of the program. Just hitting `return` at the prompt will reprint the
paragraph.
I wanted to write a program that would read in a text file in
natural language (such as English) and answer questions about that
text file. I thought this might be a complicated task, and I was
right -- it took me over 800 bytes. Of course, it doesn't always
work, but that's AI for you.
If you're curious as to how it works, I guess you could feed in the
source as the input file and ask "How does this work?" at the prompt,
but I'm not guaranteeing any results...
This program accepts the name of a text file as the first
parameter. For example, to run it on the supplied data file called
'info' you would type 'schnitzi info'. It echoes the file, then
gives you a prompt where you may type in questions about that text.
The more words you use which are actually present in the text file,
the better results you get. You'll need to hit <ctrl-c> to break out
of the program. Just hitting <return> at the prompt will reprint the
paragraph.
### Compilation notes:
If you're curious as to how it works, I guess you could feed in the
source as the input file and ask "How does this work?" at the prompt,
but I'm not guaranteeing any results...
- The use of 'strcasecmp' may be non-standard. 'strcmp' can be substituted for
it, with a slight performance penalty.
Compilation notes:
- This program depends on the first command-line parameter, typically called
argv[0], to hold the name of the executable. It is my understanding that this
property of argv[0] is not guaranteed on some systems.
o The use of 'strcasecmp' may be non-standard. 'strcmp'
can be substituted for it, with a slight performance penalty.
### Obfuscation:
o This program depends on the first command-line parameter, typically
called argv[0], to hold the name of the executable. It is my under-
standing that this property of argv[0] is not guaranteed on some
systems.
- It uses a hidden string to test for punctuation.
This program is obfuscated in the following ways:
- The layout, variable names, and expression format have been chosen in such a
way as to cause visual confusion.
o It uses a hidden string to test for punctuation;
- It uses uses external 'system' calls to echo the text file and break up the
question into individual words with a recursive call.
o The layout, variable names, and expression format
have been chosen in such a way as to cause visual confusion;
- It uses a clever hack to simulate artificial intelligence.
o It uses uses external 'system' calls to echo the text
file and break up the question into individual words with a
recursive call;
o It uses a clever hack to simulate artificial intelligence.
The text for the info file, by the way, consists largely of headlines
from the Weekly World News.
The text for the info file, by the way, consists largely of headlines
from the Weekly World News.
## Copyright and CC BY-SA 4.0 License:
+2 -2
View File
@@ -13,9 +13,9 @@
( lll>l1 ) li|=! ( l[3*l1+++3
] -ll[strlen ( ll)-1] ) ;return
( li ) ;}main ( ll,lll
) char*lll[];{char l1 [ 111][21],li1[111][21 ] ,il1[111],i1l
) char*lll[];{if(ll<2)return 1;char l1 [111][21], li1[111][21],il1[111],i1l
[ 111 ] ;int lli,l11,l1l,li/* ( */,ll1,il,l;FILE*f;if(ll-2
) {f=fopen ( lll[1],"r" ) ;lli=l=ll1=il=!1;while
) {f=fopen ( lll[1],"r" );if(!f)return 1;lli=l=ll1=il=!1;while
( fscanf(f,"%s",l1[lli] ) +1){li=ii ( l1[lli],3
) ;iii ( l1[lli] ) ;l1l=l11=!1;while
( l1l>-ll ) {iii ( lll[-l1l]