Presentation on string.h<br />
String.h- This header file defines several  functions<br />to manipulate C strings and arrays.<br />Functions declared in ...
Memcpy:-<br /> Use<br />Copy block of memory<br />  SYNOPSIS<br />#include <string.h> void *memcpy(void *s1, const void *s...
Example<br />/* memcpy example */<br />#include <stdio.h><br />#include <string.h><br /> int main ()<br />{  <br />char st...
memmove<br />memmove<br />Memmove:-<br />Use<br />Move block of memory<br />SYNOPSIS<br />#include <string.h> void *memmov...
Example<br />/* memmove example */<br /> #include <stdio.h><br /> #include <string.h><br />int main ()<br /> {<br />    ch...
Memcmp :-<br />Use<br />Compare two blocks of memory<br />SYNOPSIS<br />#include <string.h> intmemcmp(const void *s1, cons...
Example<br />/* memcmp example */<br />#include <stdio.h><br />#include <string.h><br /> <br />int main ()<br />{<br />  c...
Memset:-<br />Use<br />Fill block of memory<br />SYNOPSIS<br />#include <string.h> void *memset(void *s, intc, size_tn); <...
Example<br />/* memset example */<br />#include <stdio.h><br />#include <string.h><br /> <br />int main ()<br />{<br />  c...
Memchr<br />Use<br />Locate character in block of memory <br />SYNOPSIS<br />#include <string.h> void *memchr(const void *...
Example<br />/* memchr example */<br />#include <stdio.h><br />#include <string.h><br /> <br />int main ()<br />{<br />  c...
Thanks  for watching  .Hope u like it…..<br />By :- NISHANK<br />
Upcoming SlideShare
Loading in …5
×

String .h

1,024 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,024
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

String .h

  1. 1. Presentation on string.h<br />
  2. 2. String.h- This header file defines several functions<br />to manipulate C strings and arrays.<br />Functions declared in string.h are extremely popular<br />since as a part of the C standard library, they are <br />guaranteed to work on any platform which supports C<br />Some of its functions are defined below .<br />
  3. 3. Memcpy:-<br /> Use<br />Copy block of memory<br />  SYNOPSIS<br />#include <string.h> void *memcpy(void *s1, const void *s2, size_tn);  <br />DESCRIPTION<br />The memcpy() function copies n bytes from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behaviour is undefined.  <br />RETURN VALUE<br />The memcpy() function returns s1; no return value is reserved to indicate an error. <br />
  4. 4. Example<br />/* memcpy example */<br />#include <stdio.h><br />#include <string.h><br /> int main ()<br />{ <br />char str1[]="Sample string"; char str2[40]; char str3[40];<br />memcpy (str2,str1,strlen(str1)+1);<br />memcpy (str3,"copy successful",16);<br />printf ("str1: %snstr2: %snstr3: %sn",str1,str2,str3); <br /> return 0;<br />}<br />Output<br />str1: Sample string<br />str2: Sample string<br />str3: copy successful<br />
  5. 5. memmove<br />memmove<br />Memmove:-<br />Use<br />Move block of memory<br />SYNOPSIS<br />#include <string.h> void *memmove(void *s1, const void *s2, size_tn);  <br />DESCRIPTION<br />The memmove() function copies n bytes from the object pointed to by s2 into the object pointed<br /> to by s1. Copying takes place as if the n bytes from the object pointed to by s2 are first copied<br /> into a temporary array of n bytes that does not overlap the objects pointed to by s1 and s2,<br /> and then the n bytes from the temporary array are copied into the object pointed to by s1. <br /> RETURN VALUE<br />The memmove() function returns s1; no return value is reserved to indicate an error. <br />
  6. 6. Example<br />/* memmove example */<br /> #include <stdio.h><br /> #include <string.h><br />int main ()<br /> {<br /> char str[] = "memmove can be veryuseful......";<br />memmove (str+20,str+15,11);<br /> puts (str);<br /> return 0;<br />}}<br />}<br />Output<br />memmove can be very very useful.<br />
  7. 7. Memcmp :-<br />Use<br />Compare two blocks of memory<br />SYNOPSIS<br />#include <string.h> intmemcmp(const void *s1, const void *s2, size_tn);  <br />DESCRIPTION<br />The memcmp() function compares the first n bytes of the object pointed to by s1 to the first <br />nbytes of the object pointed to by s2. The sign of a non-zero return value is determined by the<br />sign of the difference between the values of the first pair of bytes that differ in the objects <br />being compared. <br /> <br />RETURN VALUE<br />The memcmp() function returns an integer greater than, equal to or less than 0, if the object<br /> pointed to by s1 is greater than, equal to or less than the object pointed to by s2 respectively. <br />
  8. 8. Example<br />/* memcmp example */<br />#include <stdio.h><br />#include <string.h><br /> <br />int main ()<br />{<br /> char str1[256];<br /> char str2[256];<br />int n;<br />size_t len1, len2;<br />printf ("Enter a sentence: "); gets(str1);<br />printf ("Enter another sentence: "); gets(str2);<br /> len1=strlen(str1);<br /> len2=strlen(str2);<br /> n=memcmp ( str1, str2, len1>len2?len1:len2 );<br /> if (n>0) printf ("'%s' is greater than '%s'.n",str1,str2);<br /> else if (n<0) printf ("'%s' is less than '%s'.n",str1,str2);<br /> else printf ("'%s' is the same as '%s'.n",str1,str2);<br /> return 0;<br />}<br />Output<br />Enter a sentence: building<br />Enter another sentence: book<br />'building' is greater than 'book'<br />
  9. 9. Memset:-<br />Use<br />Fill block of memory<br />SYNOPSIS<br />#include <string.h> void *memset(void *s, intc, size_tn); <br /> DESCRIPTION<br />The memset() function copies c (converted to an unsigned char) into each of the first n bytes <br />of the object pointed to by s.  <br />RETURN VALUE<br />The memset() function returns s; no return value is reserved to indicate an error. <br />
  10. 10. Example<br />/* memset example */<br />#include <stdio.h><br />#include <string.h><br /> <br />int main ()<br />{<br /> char str[] = "almost every programmer should know memset!";<br />memset (str,'-',6);<br /> puts (str);<br /> return 0;<br />}<br />Output<br />------ every programmer should know memset!<br />
  11. 11. Memchr<br />Use<br />Locate character in block of memory <br />SYNOPSIS<br />#include <string.h> void *memchr(const void *s, intc, size_tn);<br /> DESCRIPTION<br />The memchr() function locates the first occurrence of c (converted to an unsigned char) in the<br /> initial n bytes (each interpreted as unsigned char) of the object pointed to by s.  <br />RETURN VALUE<br />The memchr() function returns a pointer to the located byte, or a null pointer if the byte does <br />not occur in the object. <br />
  12. 12. Example<br />/* memchr example */<br />#include <stdio.h><br />#include <string.h><br /> <br />int main ()<br />{<br /> char * pch;<br /> char str[] = "Example string";<br />pch = (char*) memchr (str, 'p', strlen(str));<br /> if (pch!=NULL)<br />printf ("'p' found at position %d.n", pch-str+1);<br /> else<br />printf ("'p' not found.n");<br /> return 0;<br />}<br />Output<br />'p' found at position 5.<br />
  13. 13. Thanks for watching .Hope u like it…..<br />By :- NISHANK<br />

×