Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

strcstr(3pub) [debian man page]

STRCSTR(3pub)						       C Programmer's Manual						     STRCSTR(3pub)

NAME
strcstr - convert memory block to printable C string notation SYNOPSIS
#include <publib.h> void strcstr(char *str, size_t max, const void *block, size_t n); DESCRIPTION
strcstr converts the contents of an arbitrary memory block (which need not be a zero terminated string) into a printable notation using normal C string literal syntax. This can be used for example to store potentially binary data in a file, or in debugging outputs. All characters for which there is a simple shorthand escape sequence (', ", ?, , a, , f, , , , v) are stored using that nota- tion. is stored as . All other non-printable characters are stored using a hexadecimal escape sequence. All other printable charac- ters are stored as is. The isprint(3) macro is used to determine whether a character is printable (i.e., whether it is printed as is, or using special notation). Therefore, the output depends on the locale. RETURN VALUE
strcstr returns nothing. EXAMPLE
The following code dumps input to the standard output in a guaranteed (modulo locale bugs) printable format. It might be used for debug- ging. #include <stdio.h> #include <publib.h> int main(void) { char line[512]; char cstr[512*(CHAR_BIT/4+1+2)+1]; /* +2 for x, +1 for , the rest to be able to store the hex code for 512 chars. */ while (fgets(line, sizeof(line), stdin) != NULL) { strcstr(cstr, sizeof(cstr), line, strlen(line)); printf("%s0, cstr); } return 0; } SEE ALSO
publib(3), strins(3) AUTHOR
Lars Wirzenius (lars.wirzenius@helsinki.fi) Publib C Programmer's Manual STRCSTR(3pub)

Check Out this Related Man Page

XMALLOC(3pub)						       C Programmer's Manual						     XMALLOC(3pub)

NAME
xmalloc, xrealloc, xfree, xstrdup, xmemdup, memdup - memory allocation functions for Publib SYNOPSIS
#include <publib.h> void *xmalloc(size_t bytes); void *xrealloc(void *ptr, size_t bytes); void xfree(void *ptr); char *xstrdup(const char *string); void *memdup(const void *mem, size_t bytes); void *xmemdup(const void *mem, size_t bytes); DESCRIPTION
These functions are utility functions for memory allocation from the publib library. xmalloc, xrealloc, and xfree are error checking ver- sions of the standard library routines malloc, realloc, and free, respectively. They are guaranteed to never return unless there was no problem: if, for example, xmalloc is unable to allocate the requested amount of memory, it prints an error message and terminates the pro- gram. Hence, the caller does not need to check for a NULL return value, and the code that calls these functions is simpler due to the lack of error checks. Similarly, xstrdup is an error checking version of the common (though not standard) strdup routine, which creates a duplicate of a string by allocating memory for the copy with malloc. (For systems that lack strdup, publib provides one in its portability module; it is always declared in <publib.h>.) memdup is similar to strdup, it creates a copy of an arbitrary memory area (the arguments are a pointer to the beginning of the area, and its size) by allocating memory for the copy with malloc. xmemdup is its error checking version. NOTE
xmalloc and xrealloc treat a request to allocate a block of 0 bytes as an error. xrealloc will allow its first argument to be NULL. SEE ALSO
publib(3), malloc(3), strdup(3) AUTHOR
Lars Wirzenius (lars.wirzenius@helsinki.fi) Publib C Programmer's Manual XMALLOC(3pub)
Man Page

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

delete non printable characters from file

i have a file which contains non printable characters like enter,escape etc i want to delete them from the file (2 Replies)
Discussion started by: alokjyotibal
2 Replies

2. Shell Programming and Scripting

removing non-printable chars from multiple files

How do I remove non-printable characters from all txt files and output the results to one file? I've tried the following: tr -cd '\n' < *.txt > out.txt and it gives ambiguous redirect error. How can I get it to operate on all txt files in the current directory and append the output to... (1 Reply)
Discussion started by: revax
1 Replies

3. HP-UX

Non-printable characters

I have been using OKI data Microline printers; models 590 and 591 to print a bar code using the following escape sequence: \E^PA^H^C00^D^C^A^A^A\E^PB^H The escape sequence is stored in a unix file which is edited using vi. Now, we are considering Microline printer model 395C and the bar code... (3 Replies)
Discussion started by: Joy Conner
3 Replies

4. Shell Programming and Scripting

Check whether there is a non printable character in the unix variables

cp $l_options $srcdirfile $destdirfile If i want to check whether there is a non printable character in the variables $l_options $srcdirfile $destdirfile how it can be done? (2 Replies)
Discussion started by: lalitpct
2 Replies

5. Shell Programming and Scripting

Removing Non-printable characters in unix file

Hi, We have a non printable character "®" in our file , we want to remove this character, we tried tr -dc '' < oldfile> newfile but this command is removing all new line entries along with the non printable character and all the records are coming in one line(it is changing the format of the... (2 Replies)
Discussion started by: pyaranoid
2 Replies

6. Shell Programming and Scripting

Converting from scientific notation to normal

Hi everyone, I need to convert some numbers that are written in scientific notation to normal notation. Here is a sample line from my data file; "1",1,-1,0,0,502,0,0.00000000000E+00,0.00000000000E+00,0.35591163544E+03,0.35591163548E+03,0.50400001928E-02,0.,-1. first of all, my data file... (4 Replies)
Discussion started by: hayreter
4 Replies

7. Shell Programming and Scripting

ksh check for non printable characters in a string

Hi All, I am trying to find non-printable characters in a string. The sting could have alphanumeric, puntuations and characters like (*&%$#.') but not non-printable (or that is what I think they are called) which are introduced when you copy any text from DOS to unix box. Input string1:... (10 Replies)
Discussion started by: dips_ag
10 Replies

8. Shell Programming and Scripting

Redirecting records with non-printable characters

Hi, I have a huge file (50 Mil rows) which has certain non-printable ASCII characters in it. I am cleaning the file by deleting those characters using the following command - tr -cd '\11\12\15\40-\176' < unclean_file > clean_file Please note that I am excluding the following - tab,... (6 Replies)
Discussion started by: rishigc
6 Replies

9. Shell Programming and Scripting

Bash - Inserting non printable character(s) in string variable

Hello. I have a string variable named L_TEMP to test a very simple filter. L_TEMP="50AwL.|KWp9jk" I want to insert a non printable character between K and W. I have try this : linux-g65k:~ # a='50AwL.|K' linux-g65k:~ # b='Wp9jk' linux-g65k:~ # L_TEMP="$a$'\x07'$b" linux-g65k:~ # echo... (6 Replies)
Discussion started by: jcdole
6 Replies