String Concatenate Functions - strcat() & strncat()

Поделиться
HTML-код
  • Опубликовано: 6 ноя 2024

Комментарии • 35

  • @yasmimvitoriasilvadeolivei488
    @yasmimvitoriasilvadeolivei488 2 года назад

    i was shearcing for a video that teach how to concatenate some caracters into a string. I never heard before about strncat..i am in love

  • @kunalsoni7681
    @kunalsoni7681 5 лет назад +19

    seriously this presentation is great and also awesome 😉😙😗😘❤

  • @myself9892
    @myself9892 4 года назад +9

    we can also write it without strcpy:
    #include
    #include
    int main()
    {
    char str1[100]="Hey";
    char str2[50]="friends";
    strcat(str1,str2);
    printf("%s",str1);
    return 0;
    }
    output : Hey friends

    • @techxplorerxxx
      @techxplorerxxx 4 года назад

      output is wrong...there will not be any blank space in output😂😂......Debug your program by yourself in detail.....It will help you in future

    • @j.r.r.tolkien8724
      @j.r.r.tolkien8724 3 года назад +3

      ​@D
      String literals are constants and using pointers we will only be able to read those strings without being able to modify them.
      strcat tries to modify the strings (concatinating them) but they are read only so you get a segmentation fault error.
      That's why we have to store strings in arrays if we want to modify them.

    • @rayaankhan787
      @rayaankhan787 2 года назад +1

      @D str1 and str2 contains the base addresses where hello and world is stored so when you are concatenating them then the address will get appended which which be causing you the error

    • @dhruvikmevada5155
      @dhruvikmevada5155 2 года назад +1

      @D *str1 is a string constant so it cant add any other char.and in strcat you are trying to add other string so compiler will give you error.
      insted of using *ptr you can use array which allow the changes.i hope this is clear to you.

    • @asmirathore1880
      @asmirathore1880 Год назад

      ​@@j.r.r.tolkien8724😊

  • @rodm8113
    @rodm8113 3 года назад

    neso is a god among men

  • @ibrahimpasha6153
    @ibrahimpasha6153 5 лет назад +1

    Sir can you please make a video on for pointer near pointer hug pointer

  • @RahulKumar-no3rs
    @RahulKumar-no3rs 5 лет назад +1

    Very beautiful

  • @DharmendraKumar-wp4ur
    @DharmendraKumar-wp4ur 5 лет назад +1

    What is the internal implementation of strrev and strcpy etc. Plz. Can you explain ?

  • @Krishna42570
    @Krishna42570 5 лет назад

    Waiting for completion of all c programs

  • @AmarKumar-vo2bv
    @AmarKumar-vo2bv 5 лет назад

    How to access 2d array using pointer arithmetic with different ways??

  • @kavinkumar-gv6xp
    @kavinkumar-gv6xp 5 лет назад +1

    I am using turbo c++ it doesn't show error when exceed the string size and it appends the strings and prints the output correctly

    • @indrobose2873
      @indrobose2873 4 года назад +1

      turbo c++ is a outdated ide bro.

    • @harshalkumar4538
      @harshalkumar4538 3 года назад

      yeah..i am using GCC compiler in Code blocks..it shows no undefined behaviour even if size of str1 is less than the size of str1 after concatenation

    • @cuteonigiri1671
      @cuteonigiri1671 Год назад

      @@harshalkumar4538 it used the memory beyond the allocated memory. if u have something stored in tht memory, it gets rewrites. is what he said

  • @kommisettyabhishek9716
    @kommisettyabhishek9716 4 года назад +1

    are char* str1 and char *str1 same ???

  • @saikrishnathota5972
    @saikrishnathota5972 5 лет назад

    Waiting for Networks sir

  • @sagarkonduri7794
    @sagarkonduri7794 Год назад

    Wht about str2 in strncat

  • @alphamath6059
    @alphamath6059 3 года назад +1

    03:57 why do you say strncat appends NULL character at the end, while listing that strncat is safer, when strcat also appends the null-character?

  • @JofIdeas
    @JofIdeas 3 года назад +1

    Why this doesn't work with
    Char *str1,*str2;

    • @PraveenKumar-hg1lf
      @PraveenKumar-hg1lf 3 года назад +3

      Because these are pointers which point to string stored in READ ONLY MEMORY which cannot be modified but since strcat() tries to modify the destination string which is not possible thus this method doesn't work.

    • @pradhanan9413
      @pradhanan9413 3 года назад

      @@PraveenKumar-hg1lf awesome explanation

  • @SivaJallipalli
    @SivaJallipalli 3 года назад

    If strncat() automatically adds null char at end, then why -1 in the 3rd argument for null char?
    can anybody help me.

    • @j.r.r.tolkien8724
      @j.r.r.tolkien8724 3 года назад

      It needs space to add the null char?

    • @cuteonigiri1671
      @cuteonigiri1671 Год назад

      @@j.r.r.tolkien8724 yeah. automatically add doesnt mean it doesnt need space. it just means that we dont need to write \0 manually like previous example strcpy. is what i think.

  • @sivathmikachavali2026
    @sivathmikachavali2026 4 года назад

    What happens in strncat function when size of str 1 is 50 and strlen of str 1 is 11?? That becomes 38 know?!!!! Plz xplain this don't neglect it!

    • @nbk330
      @nbk330 4 года назад

      i m thinking this too..ny one please answer..??

    • @pradhanan9413
      @pradhanan9413 3 года назад

      Yeah correct

    • @006daredevil
      @006daredevil 2 года назад

      Yes it means that in str1 the remaining space left is 38 so it can append upto more 38 characters including a null character. but if s2 contains more then 38 characters to append to s1 then it will result in undefined behaviour.