Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

strncpy(9r) [osf1 man page]

strncpy(9r)															       strncpy(9r)

NAME
strncpy - General: Copies a null-terminated character string with a specified limit SYNOPSIS
char * strncpy( char *s1, char *s2, int n ); ARGUMENTS
Specifies a pointer to a buffer of at least n bytes. Specifies a pointer to a string (an array of characters terminated by a null charac- ter). Specifies the number of characters to be copied. DESCRIPTION
The strncpy routine copies string s2 to buffer s1. The routine stops copying after it copies a null character or n characters, whichever comes first. If the length of s2 as determined by the null character is less than n, the routine pads s1 with null characters. RETURN VALUES
The strncpy routine returns a pointer to /NULL at the end of the first string (or to the location following the last copied character if there is no NULL). The copied string will not be null terminated if the length of s2 is n characters or more. SEE ALSO
Routines: bcopy(9r), blkclr(9r), copystr(9r), ovbcopy(9r), strcpy(9r) strncpy(9r)

Check Out this Related Man Page

bcopy(9r)																 bcopy(9r)

NAME
bcopy - General: Copies a series of bytes with a specified limit SYNOPSIS
void bcopy( char *b1, char *b2, int n ); ARGUMENTS
Specifies a pointer to a byte string (array of characters). This pointer can reside in kernel address space or in user address space. Specifies a pointer to a buffer of at least n bytes. This pointer can reside in kernel address space or in user address space. Specifies the number of bytes to be copied. DESCRIPTION
The bcopy routine copies n bytes from string b1 to buffer b2. No check is made for null bytes. The copy is nondestructive, that is, the address ranges of b1 and b2 can overlap. RETURN VALUES
None EXAMPLES
The following code fragment shows a call to bcopy: . . . struct tc_slot tc_slot[TC_IOSLOTS]; . . . char *cp; . . . bcopy(tc_slot[index].modulename, cp, TC_ROMNAMLEN + 1); . . . SEE ALSO
Routines: blkclr(9r), copystr(9r), ovbcopy(9r), strcpy(9r), strncpy(9r) bcopy(9r)
Man Page

13 More Discussions You Might Find Interesting

1. Programming

strncpy(ver, buffer2 +5,2);

Hi, Can someone help me understand this code? strncpy(job, buffer2,5); strncpy(ver, buffer2 +5,2); Thanks for all the help! (1 Reply)
Discussion started by: whatisthis
1 Replies

2. UNIX for Advanced & Expert Users

sending a null character to a terminal

I'm testing out some ESMTP AUTH stuff, and it requires that the username and password be on the same line separated by a null character. Does anyone know how to echo the ASCII null character? Thanks, Alex (3 Replies)
Discussion started by: vertigo23
3 Replies

3. UNIX for Dummies Questions & Answers

Null Characters

How do I get rid of null characters/strings in a unix text file. I need to use this in a script. When I use dev/null it puts null characters in my file and makes it larger. Please help (5 Replies)
Discussion started by: alnita
5 Replies

4. UNIX for Dummies Questions & Answers

How to remove null characters from file?

I'm trying to remove the null characters from a file and copy it to std output. I'm using emacs and I create the following one line bash file (followed by the error messages): sed -e 's/^@//' <ConfigItemReplicator.install.log /usr/bin/bash: -c: line 0: unexpected EOF while looking for... (1 Reply)
Discussion started by: siegfried
1 Replies

5. Shell Programming and Scripting

Extract the last character of a string

How can I extract the last character of a string (withou knowing how many characters are in that string ! ) (8 Replies)
Discussion started by: annelisa
8 Replies

6. UNIX for Dummies Questions & Answers

removing characters

Hi all, Any help on how to do the following? :eek: I have an infile as follows: _thisishowyouwritehelloworld _thisisalsohowyouwritehelloworld2 I want to delete the characters from "_" to "how" and be left with: youwritehelloworld youwritehelloworld2 I am able to do delete from a... (2 Replies)
Discussion started by: dr_sabz
2 Replies

7. UNIX for Dummies Questions & Answers

write string of characters to file

Hi, I have a text file with a very long string of characters, like "ACGCTTGCAA...", and I want to make another file with 36 characters from this string file every 4 lines like: character of position 1 to position 36 of the string file, position 2-37, position 3-38 ... position... (2 Replies)
Discussion started by: fadista
2 Replies

8. Shell Programming and Scripting

Replacing one Char in a string of variable length

Hi all, I am trying to find the best way of making a change to 1 char in a string, the string can be between 1 and 14 characters. I am reading a line in from a file which contains 012341231231:2:102939283:NNN: Require :NBN: 012838238232:3:372932:NNN: Require :NNB: I need to change 1 N or a... (8 Replies)
Discussion started by: nkwilliams
8 Replies

9. Shell Programming and Scripting

NULL in between, at begining or at end of line - convert to space

How to replace null with space? I want to make each line with 80 characters. If any line contains only 5 characters and remaining is null, then i want to make it as 80 characrets where 5 is original characters and remaining 75 characters will be null.. NULL can come in between the line,... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

10. UNIX for Advanced & Expert Users

How would I create a NULL terminated file in Unix under Bash?

I am testing some file routines against potential "nasty name" Unix files, such as those with a CR, LF, in the middle or NULL terminated, utf multi-byte character. So, under Bash, I want some way of: mv "name" "name\0" with the \0 a real NULL. Against all my efforts, I have not been... (2 Replies)
Discussion started by: drewk
2 Replies

11. UNIX for Advanced & Expert Users

Another binary manipulation thread.

As bash cannot cope with a byte value of zero inside a variable then this is a workaround. This code is a DEMO to show how to create a _string_variable_ containing all of the values of 1 to 255 as single characters and 0, (zero), as a two byte character set of \0. The real binary files are 512... (20 Replies)
Discussion started by: wisecracker
20 Replies

12. Linux

Issue in inserting null string in array

I am getting some values from a file and putting them in an array..but the null strings are not getting passed to the array. So during printing the elements ,the null string is not showing in the output. during array size calculation it is also excluding null.Please let me know how to do it. # cat... (2 Replies)
Discussion started by: millan
2 Replies

13. Shell Programming and Scripting

Generate a string of alphanumeric characters

Hi, I want a script of a code that will allow me to generate all possible combinations of alphanumberica characters of length 12 such that each string will contain numbers and either small or capital letters. For example a string may look like this: 123AB45cd678. (11 Replies)
Discussion started by: faizlo
11 Replies