Reputation: 3235
Here is my code:
#include <string.h>
#include <stdio.h>
int main( int argc, char** argv)
{
static char tmpBuf[ 4 ];
long idx;
unsigned int cks;
int bufLen = strlen(argv[1]);
for ( idx = 0, cks = 0; idx < bufLen; idx++) {
unsigned char c = argv[1][idx];
printf("Char=%c|", c);
cks += c;
}
sprintf( tmpBuf, "%03d", (unsigned int)( cks % 256 ) );
printf( "\n%s\n", tmpBuf );
return 0;
}
Basically it sums up all the characters which may contain non printable ones. In my testing:
>./a.out "\1"
Char=\|Char=1|
141
You can see that the program interprets "\1" as 2 separate characters instead of an escaped one char.
How can I make the code take escape to take non-printable char?
Upvotes: 0
Views: 669
Reputation:
You want to tell your shell to interpret escape sequences correctly. If you're using Bash:
$ ./a.out $'\1'
Upvotes: 4