Wednesday, July 3, 2019

strcpy in c language

#include <stdio.h>
#include <string.h>


int main()
{
    char str1[10]= "hello";
    char str2[10];
    char str3[10];
    strcpy(str2, str1);
    strcpy(str3, "world");
    puts(str2);
    puts(str3);
    return 0;
}

strncpy example in c language

/* strncpy example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str1[]= "To be or not to be";
  char str2[40];
  char str3[40];

  /* copy to sized buffer (overflow safe): */
  strncpy ( str2, str1, sizeof(str2) );

  /* partial copy (only 5 chars): */
  strncpy ( str3, str2, 5 );
  str3[5] = '\0';   /* null character manually added */

  puts (str1);
  puts (str2);
  puts (str3);

  return 0;
}

memcpy function in C language

/* A C program to demonstrate working of memcpy */
#include <stdio.h>
#include <string.h>

int main ()
{
char str1[] = "Geeks";
char str2[] = "Quiz";

puts("str1 before memcpy ");
puts(str1);

/* Copies contents of str2 to sr1 */
memcpy (str1+5, str2, sizeof(str2));

puts("\nstr1 after memcpy ");
puts(str1);

return 0;
}

memset example in c program

// C program to demonstrate working of memset()
#include <stdio.h>
#include <string.h>

int main()
{
    char str[50] = "GeeksForGeeks is for programming geeks.";
    printf("\nBefore memset(): %s\n", str);

    // Fill 8 characters starting from str[13] with '.'
    memset(str + 13, '*', 8*sizeof(char));

    printf("After memset():  %s", str);
    return 0;
}




https://drive.google.com/file/d/1xYaDVv94E0CW72A67l5umgmtn1NDT5J2/view?usp=sharing

stm32 uart communication working code

python class topic video