Commit b08461fd authored by dragontamer lance's avatar dragontamer lance

fixes for spurious null characters and other issues. Updated readme to be a...

fixes for spurious null characters and other issues. Updated readme to be a little more explanatory.
parent 20353295
......@@ -9,4 +9,22 @@ Notes:
Each of the comma separated numbers is actually just a single character of
an ascii string, represented in decimal form for some reason.
Also note that each string should be null terminated. Yeah, I know that's annoying. Might try to make it less annoying in the future.
Also note that each string should be null terminated. Yeah, I know that's
annoying. Might try to make it less annoying in the future.
In the meantime, here's how you can type null characters in a few
editors/platforms.
In emacs, `C-q 0 <RET>`.
In vim (and maybe vi), `ctrl-v [email protected]`.
In Windows, I don't know. Maybe try
alt+<numpad 0><numpad 0><numpad 0> with the num lock on. Or try [email protected]
Be sure to use an editor that supports inserting special characters.
Notepad may not be sufficient.
In OS X, you can run emacs from a terminal and use the emacs instructions.
There may be other ways, but I don't use OS X often enough to know them for
sure. [email protected] may also be worth a try here.
......@@ -30,7 +30,12 @@ int main(int argc, char **argv)
achar = fgetc(infile);
if(achar != EOF)
{
printf("S");
/*
this isn't actually right. It assumes that each line only contains
one string, when in fact strings are simply signified as starting
with 'S' and ending with a null (,0) and a semicolon.
*/
printf("S");
}
else
{
......@@ -41,8 +46,12 @@ int main(int argc, char **argv)
{
printf("%d,",achar);
}
else
else /* ; or eof */
{
if(achar==';')
{
putchar('0');
}
printf("%d",achar);
}
achar = fgetc(infile);
......
......@@ -39,18 +39,38 @@ int main(int argc, char **argv)
str[i]=achar;
i++;
}
printf("%c",(char)atoi(str));
int isok=0;
i=0;
while(i<3 && str[i] != '\0' && isok == 0)
{
if(!isascii(str[i]) || str[i] == '\0')
{
isok=1;
}
i++;
}
if(isok==0 && atoi(str) != '\0')
{
printf("%c",(char)atoi(str));
}
str[0]='\0';
str[1]='\0';
str[2]='\0';
i=0;
} /* ';' reached */
if(achar == ';')
printf(";");
{
putchar('\0');
putchar(';');
}
/* print out rest of line since we don't know what it is yet */
while(achar != '\n' && achar != EOF && achar != 'S')
while(achar != '\n' && achar != EOF && achar != 'S' && isascii(achar))
{
printf("%c",(achar=fgetc(infile)));
achar=fgetc(infile);
if(achar != '\0')
{
printf("%c",achar);
}
}
} /* != EOF */
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment