Thanks Akshay!
Seems I understand sprinf() to return a string, but could you please explain this line?
suppose the input string is "A test string" from start = 3, end = 9.
Or, more specifically the part "%.*s", which I assume is for the formats. How does it work? Thanks again.
You need to look at the man page for the printf() function. You'll see that:
is shorthand for:
without the need for the space for the intermediate format string.
This User Gave Thanks to Don Cragun For This Post:
void main()
{
int a={1,2,3,4,5,6,7,8,9,10};
int *p=a;
int *q=&a;
cout<<q-p+1<<endl;
}
The output is 10, how?
if we give cout<<q it will print the address, value won't print....
if we give cout<<p it will print the address, value won't print....
p has the base addr; q... (1 Reply)
All ..
I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced
code:
int cnt1;
char *t_array;
char *f_array;
for(cnt1=0; cnt1<1000; cnt1++)
{
t_array =... (1 Reply)
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Hi all,
Can anyone provide help with getting the right syntax regarding array/pointers in C in the following code? Can't locate a specific example which clarifies this...
Say I declare a typedef to an array of pointers to some type...
/**
* An array of ptrs to sections
*/
typedef... (4 Replies)
if i create an array of pointers to a structure "struct node" as:
struct node *r;
and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as:
r=multiplty(.......) /*some parameters*/
is... (2 Replies)
Hi guys,
Besides the points bellow, what would best practices for scripting be ?
1) set the PATH
2) unset the current environment (set -u ?)
3) (re)set the IFS to default value - space (IFS="" <- is this correct ?)
4) check the return code for each action inside the script (cd, rsync,... (1 Reply)
I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines?
I have talked to one of the curators of the forum, but I am still not quite clear.
Here... (1 Reply)
Discussion started by: yifangt
1 Replies
LEARN ABOUT SUNOS
strspn
strcpy(9F) Kernel Functions for Drivers strcpy(9F)NAME
strcpy, strlcat, strlcpy, strncat, strncpy, strspn - String operations.
SYNOPSIS
#include <sys/ddi.h>
char *strcpy(char *dst, const char *src);
size_t strlcat(char *dst, const char *src, size_t dstsize);
size_t strlcpy(char *dst, const char *src, size_t dstsize);
char *strncat(char *restrict s1, const char *restrict s2, size_t n);
char *strncpy(char *dst, const char *src, size_t n);
size_t strspn(const char *s1, const char *s2);
INTERFACE LEVEL
Solaris DDI specific (Solaris DDI).
PARAMETERS
dst, src Pointers to character strings.
s1, s2 Pointers to character strings.
n Count of characters to be copied.
DESCRIPTION
The arguments dst, src, s1 and s2 point to strings. The strcpy(), strlcpy(), strncpy(), strlcat() and strncat() functions all alter their
first argument. These functions do not check for overflow of the array pointed to by the first argument.
strcpy()
The strcpy() function copies characters in the string src to dst, terminating at the first null character in src, and returns dst to the
caller. No bounds checking is done.
strncpy()
The strncpy() function copies src to dst, null-padding or truncating at n bytes, and returns dst. No bounds checking is done.
strlcpy()
The strlcpy() function copies a maximum of dstsize-1 characters (where dstsize represents the size of the string buffer dst) from src to
dst, truncating src if necessary. The result is always null-terminated. The function returns strlen(src). Buffer overflow can be checked
as follows:
if (strlcpy(dst, src, dstsize) >= dstsize)
return (-1);
strncat()
The strncat() function appends a maximum of n characters. The initial character of s2 overrides the null character at the end of s1.
strlcat()
The strlcat() function appends a maximum of (dstsize- strlen(dst)-1) characters of src to dst (where dstsize represents the size of the
string buffer dst). If the string pointed to by dst contains a null-terminated string that fits into dstsize bytes when strlcat() is
called, the string pointed to by dst is a null-terminated string that fits in dstsize bytes (including the terminating null character) when
it completes, and the initial character of src overrides the null character at the end of dst. If the string pointed to by dst is longer
than dstsize bytes when strlcat() is called, the string pointed to by dst is not changed. The function returns min{dst-
size,strlen(dst)}+strlen(src). Buffer overflow can be checked as follows:
if (strlcat(dst, src, dstsize) >= dstsize)
return -1;
strspn()
The strspn() function returns the length of the initial segment of string s1 that consists entirely of characters from string s2.
RETURN VALUES
strcpy(), strncat() and strncpy() return dst.
For strlcat(), strlcpy() and strspn(), see the Description section.
CONTEXT
These functions can be called from user or interrupt context.
SEE ALSO strlen(9F), strcmp(9F), bcopy(9F), ddi_copyin(9F)
Writing Device Drivers
SunOS 5.10 7 Sep 2004 strcpy(9F)