January 18, 2021

C String Library and String Copy Function – strcpy()



C Programming: C String Library and strcpy() Function in C Programming.
Topics discussed:
1) Introduction to C string library.
2) String Copy function (strcpy).
3) The prototype of strcpy() function.
4) Example use of strcpy() function.
5) The prototype of strncpy() function.
6) Example use of strncpy() function.

C Programming Lectures:

Follow Neso Academy on Instagram: @nesoacademy(
Follow me on Instagram: @jaspreetedu(

Contribute:

Memberships:

Books:

Website ►
Forum ►
Facebook ►
Twitter ►

Music:
Axol x Alex Skrindo – You [NCS Release]

#CProgrammingByNeso #CProgramming #Strings #StringLibrary #strcpy #StringsInC

Nguồn: https://ka-nom.com/

Xem thêm bài viết khác: https://ka-nom.com/cong-nghe/

Related Posts

[Lập trình C/C++] Bài 33. Xây dựng hàm so sánh 2 chuỗi có phân biệt hoa thường – strcmp

July 8, 2020

July 8, 2020 5

– Source code: – Nguyên tắc so sánh 2 chuỗi: Ví dụ: so sánh 2 chuỗi s1, s2 – Lấy...

Perfect SKX Mods Part 1.5 – Strapcode/Miltat Super Oyster!!

July 11, 2020

July 11, 2020 28

**BUY A STRAPCODE HERE FOR YOUR SKX!!!** *CHECK OUT MY TOP VALUE WATCHES AND ACCESSORIES ON AMAZON!* *USE THE CODE...

Stormracer Extreme Pro RTR (500103020)

July 9, 2020

July 9, 2020 31

Extrem clever — extrem gut! Stormracer Extreme Pro – die innovative Weiterentwicklung auf dem aktuellen CV-10 Chassis, fahrfertig aufgebaut. Das...

Draw Hyperrealistic Strawberry | Step-by-step Tutorial

July 8, 2020

July 8, 2020 35

GOOD NEWS… I just published my first BEGINNER to ADVANCED Sketching Course on Udemy. It’s currently on sale (for flat...

Descargar, instalar y activar Stellar Data Recovery Professional 9 – Última versión – Links directos

July 7, 2020

July 7, 2020 38

En esta ocasión les traigo este software de recuperación de datos con funciones de reparación de fotos y videos: –...

Using StringStream to extract integers from strings in C++ (HackerRank)

July 12, 2020

July 12, 2020 10

Solution for StringStream in C++, one of the most popular HackerRank problem solving questions. Learn how to use StringStream in...

Stick War Legacy⚔Hack😂Destroy Base LV9999…⚔KasubukTQ

July 10, 2020

July 10, 2020 27

Stick War Legacy | Mod 999999999 Giant Lava siêu mạnh | Stick War Legacy Hack | KasubukTQ ⬇️Cách tải game...

Hack level (cấp) game Stickman Legends, hack vàng, hack ngọc, hack chìa khóa huyền thoại

July 10, 2020

July 10, 2020 40

Hướng dẫn Hack level cấp game Stickman Legends, hack vàng, hack ngọc, hack chìa khóa huyền thoại Khi chúng ta...

Is Your Child Strong-Willed or Weak-Willed?

July 8, 2020

July 8, 2020 15

What we often call a strong-willed child, Charlotte Mason would call a weak-willed child. // MENTIONED The Way of the...

Java cơ bản 44: StringBuilder và StringBuffer

July 9, 2020

July 9, 2020 1

Chào các bạn, Blog StudyAndShare được xây dựng với mục đích chia sẻ kiến thức giữa cộng động những người...

Stray Kids (스트레이 키즈) Members Profile (Birth Names, Positions etc..) [Get To Know K-Pop] (2019 ERA)

July 9, 2020

July 9, 2020 21

NEW UPDATED PROFILE & POSITIONS HERE – Learn about boy group Stray Kids (스트레이 키즈) in their members profile including...

How to Draw Strawberry Easy

July 9, 2020

July 9, 2020 13

Thanks for watching our Channel. how to draw strawberry fruit, how to draw strawberry easy, how to draw strawberry step...

DIY Planner Dashboard | Sticky Notes & Page Flags

July 13, 2020

July 13, 2020 22

Have you seen these videos? Plan with Me | Erin Condren | Bee & Honey Theme Plan with Me &...

State of decay 2 codex crack + install app failed ..fixed 100%

July 7, 2020

July 7, 2020 41

HI friends In this video STATE OF DECAY 2 CODEX CRACK DOWNLOAD + INSTALLATION. you can see the game installation...

How Live Stream A Pre Recorded Video to Facebook Using OBS in 2019

July 9, 2020

July 9, 2020 25

How To Live Stream a Pre Recorded Video to Facebook Using OBS Studio In this tutorial, I will show you...

Comments
  • This is the correct code for strncpy
    #include <stdio.h>
    #include <string.h>
    int main()
    {
    char str1[6] = "Hello";
    char str2[5] = "";
    strncpy(str2, str1, sizeof(str2) – 1);
    printf("%s", str2);
    return 0;
    }
    (OR)
    #include <stdio.h>
    #include <string.h>
    int main()
    {
    char str1[6] = "Hello";
    char str2[5];
    strncpy(str2, str1, sizeof(str2));
    str2[sizeof(str2)-1]='';
    printf("%s", str2);
    return 0;
    }

    Output for both the programs : Hell

  • at 6:32 the output is "Hell" but on my computer it's showing "HellHello" why is that????
    and when source>= destination so that means at 6:32 strncpy() din put a null character in str2[4] then why your output is "Hell", without showing an undefined behaviour ? tho in my computer it showed "HellHello" with same code

  • What do you mean by prototype here. I saw in some previous videos too but din quite understand what is prototype. We're using only strcpy(destination,source) but the prototype consist more. What is prototype and what it is used for???

  • For str1[6] and str2[4]
    We have to add str2[4]='' after the strncpy line.Otherwise it will print HellHello. (5:25)

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char str1[6]="Hello";
    char str2[4];
    strncpy(str2,str1,sizeof(str2));
    str2[4]='';
    printf("%s",str2);
    return 0;
    }

  • The correct code to print "Hell" for str2 is (5:25) :

    #include <stdio.h>

    #include <string.h>

    int main(){

    char str1[6] = "Hello";

    char str2[5];

    strncpy(str2, str1, sizeof(str2)-1);

    printf("%s" , str2);

    return 0;

    }

    Please check if I am correct.
    (the problem was about the string terminator of str2 as I mentioned in my previous comment).

  • In the case of strncpy : (5:25)
    If str2 is "Hell". As str2 is of size 4. then what about the string terminator?
    shouldn't it be "Hel" only?

  • The prototype is having arguments as char pointers. But, the problem explanation has char arrays. Why because we cannot change or modify char pointers? But, we can copy, right?

  • But sir why not use a for loop like this

    char str1[6] = "Hello";
    char str2[6];

    for(int i = 0; i < sizeof(str1); ++i)
    str2[i] = str1[i];

    But anyways fantastic lessons:)

  • char c=48;

    int i, mask=01;

    for(i=1; i<=5; i++)

    {

    printf("%c", c|mask);

    mask = mask<<1;

    }

    anyone explain me output of this..plz help

  • @neso Academy, what if size or str1 and str2 where both 5, adding the nul byte at the end wouldn’t overwrite ‘o’??

  • #include<stdio.h>

    #include<string.h>

    int main()

    {

    char str[6]="hello";

    char str1[0];

    strcpy( str1,str);

    printf("%s",str1);

    }
    but this code is exuted in my computer please help………….
    output is hello

  • Fantastic vedio sir it is really helpful to understand full concept we are really thankful to you sir 👍🙏🙏🙏

Leave a Reply

Your email address will not be published. Required fields are marked *