Wednesday, June 13, 2012
strncpy function in C
strncpy string function is used to copy the specified no. of characters from one string to another string. This is similar to strcpy string function. But the difference is , strcpy is just copies all the characters from source string to destination string until source reaches termination character. whereas strncpy copies only n characters from the source string to destination string if there is no terminal character. If any terminal character is ther before the nth character, it will stop the copying. strncpy is not a null termination character function. So strncpy is more advisable to use over strcpy. Because memory overwriting will not happen in strncpy.
Syntax for strncpy:
strncpy function in C using array:
strncpy function in C using pointers:
Syntax for strncpy:
char *strncpy(char *dest, const char *src, size_t n);
strncpy function in C using array:
//using arrays , need to move the string using index void strcpy_arry(char * dest, char *src) { int i=0; while((dest[i]=src[i])!='0円') i++; }
strncpy function in C using pointers:
//using pointers, need to move the position of the pointer void strcpy_ptr(char *dest, char *src) { while((*dest=*src)!='0円') { src++; dest++; } }
Subscribe to:
Post Comments (Atom)
Popular Posts
-
A universally unique identifier ( UUID ) is an identifier standard used in software construction, standardized by the Open...
-
Recently I started working on Japser Studio professional for my new project Cloud to generate the reports. I was very new to all cloud ...
-
Below is C program for AVL Tree implementation. #include<stdio.h> #include<malloc.h> typedef struct bst { int info; int hei...
-
strcmp is another string library function which is used to compare two strings and returns zero if both strings are same , returns +ve valu...
-
One of the complex operation on binary search tree is deleting a node. Insertion is easy by calling recursive insertion. But deletion wont...
-
We have recently faced one tricky issue in AWS cloud while loading S3 file into Redshift using python. It took almost whole day to inde...
-
Object slicing: when a derived class object is assigned to a base class object. only base class data will be copied from derived class and...
-
We have faced lot of weird issues while loading S3 bucke t files into redshift. I will try to explain all issues what we faced. Before go...
-
Below code is to find the cube root of a given integer number with out using pow math library function. Its very simple and brute force...
-
Recently we faced one issue in reading messages from SQS in AWS cloud where we are processing same message multiple times. This issue we...
No comments:
Post a Comment