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:
1 parent
9e07c1ae91
commit
a411e62815
2 files changed
+69
-55
No files matched your search
+67
-53
@@ -9,22 +9,44 @@
|
|||||||
|
|
||||||
make all
|
make all
|
||||||
|
|
||||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this use `fgets()`
|
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to not
|
||||||
not `gets()` to make it safer. Thank you Cody for your assistance!
|
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
|
file a file containing some text
|
||||||
|
|
||||||
## Judges' comments
|
## Try:
|
||||||
|
|
||||||
After this program prints the contents of 'file', ask it
|
./schnitzi schnitzi.info
|
||||||
some questions related to the text.
|
# 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?
|
Who is Mark Schnitzius?
|
||||||
What exactly does this program do?
|
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?
|
Is it true that Elvis is alive?
|
||||||
Do colorless green ideas sleep furiously?
|
Do colorless green ideas sleep furiously?
|
||||||
|
|
||||||
We suggest you try using the body (minus the header and signature line)
|
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. :-)
|
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
|
NOTE: The author may also be contacted at: marks@aldrin.ksc.nasa.gov.
|
||||||
running this entry.
|
|
||||||
|
|
||||||
NOTE: this entry will likely segfault if you do not provide it with a data
|
## Author's comments:
|
||||||
file.
|
|
||||||
|
|
||||||
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
|
If you're curious as to how it works, I guess you could feed in the
|
||||||
natural language (such as English) and answer questions about that
|
source as the input file and ask "How does this work?" at the prompt,
|
||||||
text file. I thought this might be a complicated task, and I was
|
but I'm not guaranteeing any results...
|
||||||
right -- it took me over 800 bytes. Of course, it doesn't always
|
|
||||||
work, but that's AI for you.
|
|
||||||
|
|
||||||
This program accepts the name of a text file as the first
|
### Compilation notes:
|
||||||
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.
|
|
||||||
|
|
||||||
If you're curious as to how it works, I guess you could feed in the
|
- The use of 'strcasecmp' may be non-standard. 'strcmp' can be substituted for
|
||||||
source as the input file and ask "How does this work?" at the prompt,
|
it, with a slight performance penalty.
|
||||||
but I'm not guaranteeing any results...
|
|
||||||
|
|
||||||
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'
|
### Obfuscation:
|
||||||
can be substituted for it, with a slight performance penalty.
|
|
||||||
|
|
||||||
o This program depends on the first command-line parameter, typically
|
- It uses a hidden string to test for punctuation.
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
- It uses a clever hack to simulate artificial intelligence.
|
||||||
have been chosen in such a way as to cause visual confusion;
|
|
||||||
|
|
||||||
o It uses uses external 'system' calls to echo the text
|
The text for the info file, by the way, consists largely of headlines
|
||||||
file and break up the question into individual words with a
|
from the Weekly World News.
|
||||||
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.
|
|
||||||
|
|
||||||
## Copyright and CC BY-SA 4.0 License:
|
## Copyright and CC BY-SA 4.0 License:
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
( lll>l1 ) li|=! ( l[3*l1+++3
|
( lll>l1 ) li|=! ( l[3*l1+++3
|
||||||
] -ll[strlen ( ll)-1] ) ;return
|
] -ll[strlen ( ll)-1] ) ;return
|
||||||
( li ) ;}main ( ll,lll
|
( 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
|
[ 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
|
( fscanf(f,"%s",l1[lli] ) +1){li=ii ( l1[lli],3
|
||||||
) ;iii ( l1[lli] ) ;l1l=l11=!1;while
|
) ;iii ( l1[lli] ) ;l1l=l11=!1;while
|
||||||
( l1l>-ll ) {iii ( lll[-l1l]
|
( l1l>-ll ) {iii ( lll[-l1l]
|
||||||
|
|||||||
Reference in new issue
Block a user