#22 C String Functions | C Programming For Beginners

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

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

  • @programizstudios
    @programizstudios  2 года назад +4

    🔥Finding it Damn Hard to Understand C Programming?
    Learn to code-the right way-with interactive lessons, quizzes & challenges. Build a strong programming base; it's IMPORTANT!
    Try Programiz PRO for Free: bit.ly/master-c-programming

    • @AbhiramDeshpande-fe1vi
      @AbhiramDeshpande-fe1vi Год назад

      #include
      #include
      int main() {
      char text1[50];
      char text2[50];
      printf("enter 1st string :",text1);
      fgets(text1,sizeof(text1),stdin);
      printf("enter 2nd string :",text2);
      fgets(text2,sizeof(text2),stdin);
      strlen(text1)>strlen(text2)?printf(" the larger string is: %s",text1):printf(" the larger string is: %s",text2);
      return 0;
      }

    • @josephnieves8175
      @josephnieves8175 Месяц назад

      Hi. I'm having problems with a question.
      Read three integers from input and assign the integers to num1, num2, and num3, respectively. Then, output the sum of the three integers, followed by a newline.
      Ex: If the input is 3 4 6, then the output is:
      13
      Ex: If the input is 8 9 5, then the output is:
      22
      Here's the code:
      #include
      int main(void) {
      int num1;
      int num2;
      int num3;
      return 0;
      }

  • @Azizam-j3c
    @Azizam-j3c Год назад +19

    Good video!
    Just a side note, strcmp() doesn't return a random value if the strings are not equal. The function compares the two strings character by character until it finds a difference, and then returns the ASCII value difference between the characters at that position. If the two strings are equal, the function returns 0. If the first character that differs is greater in the first string, the function returns a positive value. If the first character that differs is greater in the second string, the function returns a negative value. Therefore, the value returned by strcmp() is deterministic based on the input strings.

  • @RalphAdrianePDilao
    @RalphAdrianePDilao 2 года назад +44

    /*Create a Program to compare two strings and print the larger string.*/
    #include
    #include
    int main() {
    char string1[40];
    char string2[40];
    int lengthOfString1;
    int lengthOfString2;
    printf("Please enter string 1: ");
    fgets(string1, sizeof(string1), stdin);
    printf("Please enter string 2: ");
    fgets(string2, sizeof(string1), stdin);
    lengthOfString1 = strlen(string1);
    lengthOfString2 = strlen(string2);
    if(lengthOfString1 > lengthOfString2){
    printf("%s", string1);
    }
    else if(lengthOfString2 > lengthOfString1){
    printf("%s", string2);
    }
    else{
    printf("Both characters has the same length.");
    }
    return 0;
    }

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

    • @qarikhalidwaheed1643
      @qarikhalidwaheed1643 Год назад +1

      @@AFCOE
      It works perfectly! I Copied it into the Programiz compiler and it works perfectly! 👍👌

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

      hi i already coded like same but i will get run program output get correct when i put print lenth of string that time size wil be show like 7-8 but i check size of letter is 6-7 what reason what mistake i don't know about this please check paste code.....

    • @ВладимирСоколовский-щ1ы
      @ВладимирСоколовский-щ1ы 10 месяцев назад

      аа

    • @918903021
      @918903021 5 месяцев назад

      @@ВладимирСоколовский-щ1ы Great job!!
      I was stucu, but with the help of your comment you got me unstuck.
      The way you used the "int leng1" helped me a lot to think.
      However what one person is saying with fgets it adds 1 on the length.
      I tried as explained in the video and I still have the same issue.
      Can someone explain?
      #include
      #include
      int main () {
      char str1[40];
      char str2[40];
      printf("Enter string1: ");
      fgets(str1, sizeof(str1), stdin);
      printf("Enter string2: ");
      fgets(str2, sizeof(str2), stdin);
      printf("String1 = %zu
      String2 = %zu
      ", strlen(str1), strlen(str2));
      if(strlen(str1) > strlen(str2)){
      printf("String1 is the lengthier, with %zu chars
      ", strlen(str1));
      }
      else if(strlen(str1) < strlen(str2)) {
      printf("String2 is the lengthier, with %zu chars", strlen(str2));
      }
      else{
      printf("Both are the same length with %zu.", strlen(str1));
      }
      return 0;
      }

  • @pokhto_k_programming
    @pokhto_k_programming Год назад +4

    "Googling things is most the important skill in programing"
    👍💯

  • @alv1947
    @alv1947 2 года назад +8

    No word to say how awesome is your work. thank you Programiz team. Simply you rock !!

  • @erl2nd
    @erl2nd Год назад +2

    Thank you so much,
    Well done and much appreciated! ☺️
    Quiz answer is: B

  • @eszterannaimre711
    @eszterannaimre711 10 месяцев назад +1

    Thank you! You are saving me from failing my course!

  • @jings0nline
    @jings0nline 2 месяца назад

    Loved watching your c programming series, come back with such contents again madam.

  • @nahomiperezflores7727
    @nahomiperezflores7727 2 года назад +4

    I love your videos, I understand them easily.
    Can you explain pointers? Pleaseee

  • @arianas7866
    @arianas7866 2 года назад +2

    For the programming exercise
    It prints the length of the string to be 1 more than it should be I can't figure out why
    This is my code:
    #include
    int main() {
    char string1[20];
    printf ("Enter string 1:");
    fgets(string1, sizeof(string1), stdin);
    printf ("
    Length: %zu", strlen(string1));
    char string2[20];
    printf ("
    Enter string 2:");
    fgets(string2, sizeof(string2), stdin);
    printf ("
    Length: %zu", strlen(string2));

    if (strlen(string1)> strlen(string2)){
    printf ("
    Sting 1 is bigger");
    }
    else if (strlen(string2) > strlen(string1)){
    printf("
    String 2 is bigger");
    }
    else {
    printf ("
    Same length");
    }
    return 0;
    }

  • @user-nt4nm4fb3u
    @user-nt4nm4fb3u 8 месяцев назад

    As always great explanation. Thank you Programiz for this amazing Tutorial series!!!!!!!!!!!
    I am really enjoying C programming with these tutorial videos!

  • @emmanuellegentil9930
    @emmanuellegentil9930 2 года назад +4

    Hello ma'am
    Nice explanation👍🏽👍🏽
    I've tried to do a program to concatenate 2 string, but this time I ask the user to input 2 strings
    int main(){
    Char name1[50];
    Char name2[50];
    // ask user to input strings
    printf("Enter string 1: ");
    fgets(name1, sizeof(name1), stdin);
    printf("Enter string 2: ");
    fgets(name2, sizeof(name2),stdin);
    //Then I've used strcat to join the 2 strings
    strcat(name1,name2);
    Printf ("%s" , name1);
    return 0;
    }
    But when I compile and run
    When I type the two strings on the compiler, it doesn't concatenate the name1 and name2????
    I gives the output into different lines
    name1
    name2
    Instead of name1 name2
    Can you please tell me what's wrong ??

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

      Use #include header file

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

      You probably don't need help for this anymore, but for those that may have the same problem, I believe the reason behind this is because of the way you're handling user input. Of course the goal is to add two strings together, but if the user enters a string that contains whitespace, then it complicates the way we gather those strings. OP knows what he's doing with getting the two strings. However, for some odd reason, using the fgets() function also "gets" the newline (
      ) character and stores it in the char array. Since the user presses Enter to complete their input, it adds that
      character at the end of whatever they typed.
      Luckily enough, the position of this
      character is always at the "strlen()" of the string, minus 1. For example, the string "Hello World", has a length of 11. If it had a newline character, then the length of the string includes that newline character. Therefore, it has a length of 12. If we were to access this character, we would simply type nameOfCharArray[12 - 1]. Then you could probably replace it with the null terminator character \0 to tell the compiler that the string ends there.
      For anyone who's experienced with C, pls correct anything I've said that is wrong, even if everything I said was wrong hahaha.

  • @MagaScampini
    @MagaScampini 5 месяцев назад +1

    In the strcat example there´s an error, when we use strcat(), the size of the destination string should be large enough to store the resultant string. If not, we will get the segmentation fault error. I don´t understand how her´s is working but if you don´t define the size of destination to be large enough to store the size of the source it´s not gonna work.

    • @hrkhrld
      @hrkhrld 3 месяца назад

      i got segmentation error idk why

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

    I was feeling sad because I was having problems, but now everything is making sense!! Thank youuu!

  • @programizstudios
    @programizstudios  2 года назад +4

    Q. Which of the following functions is used to join two strings?
    a. strjoin()
    b. strcat()
    c. join()
    d. cat()

  • @stealthy_doctor
    @stealthy_doctor 4 месяца назад

    great video!
    for the quiz to join two together is the strcat() function and this is the program to print the larger input:
    #include
    #include
    int main() {
    // Write C code here
    char word1[20];
    char word2[20];

    printf("Enter the first word: ");
    fgets(word1, sizeof(word1), stdin);//this will get the entier input with spaces


    printf("Enter the second word: ");
    fgets(word2, sizeof(word2), stdin);

    if(strlen(word1)

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

    Please do atleast one video daily, can't wait !

  • @onomemafuru9496
    @onomemafuru9496 Год назад +1

    For the string length calculation of "C programming" is it the white space between C and programming that is counted or the terminal \0?

  • @yogithabale
    @yogithabale 3 месяца назад +1

    mam , strcat type function is showing error - segmentation fault

  • @SaiSiddartha-l9o
    @SaiSiddartha-l9o 4 месяца назад

    The answer is option B mam thank you
    😊😊😊

  • @segunomotosho1131
    @segunomotosho1131 Год назад +2

    #include
    #include
    int main() {
    char input1[30];
    char input2[30];
    printf("enter the first value:
    ");
    fgets(input1, sizeof(input1), stdin);
    printf("enter the second value:
    ");
    fgets(input2, sizeof(input2), stdin);
    if (strlen(input1)>strlen(input2))
    {
    printf("%s", input1);
    }
    else if(strlen(input2)>strlen(input1)){
    printf("%s", input2);
    }
    else{
    printf("Both Characters has the same length");
    }
    return 0;
    }

  • @governorvantarus
    @governorvantarus 7 месяцев назад

    Very well explained, thumbs up 👍

  • @Ech-chatouiMohammed
    @Ech-chatouiMohammed Месяц назад

    we appriciate your help

  • @laurenzwegler7141
    @laurenzwegler7141 2 месяца назад +1

    //Incredibly secure program, which compares string lenghts:
    //I remembered video #10, are you proud of me? XD
    #include
    #include
    int main()
    {
    printf("Enter string one: ");
    char string1[50];
    gets(string1);
    printf("Enter string two: ");
    char string2[50];
    gets(string2);
    printf("
    The longer string is: ");
    (strlen(string1)) > strlen(string2) ? printf(string1) : printf(string2);
    return 0;
    }

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

    NOW I ALREADY LOVE C 😍

  • @onic9623
    @onic9623 Год назад +2

    5:53 why text1 ?
    pls can anyone explain

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

    visual studio 2022 wants me to use strcat_s instead of strcat and asks for a buffer size, but when I give it a buffer size equal to the size of text1 + text2 (which should be 2 more than it needs since I believe sizeof also includes the \0), it says that it overflows the buffer and the buffer is too small

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

    Why does my strcmp function output -1 when it supposed to output -4?

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

    Say every line meaning mam... It will help to crack interview..

  • @nanimg3512
    @nanimg3512 2 года назад +3

    🥺🥺🥺 Thank you every much ...🙏

  • @nihatdonmzov4166
    @nihatdonmzov4166 Год назад +1

    Thank you so much for the video

  • @Selcuk._._
    @Selcuk._._ 5 месяцев назад

    How can we use strlen() at 4:56? strlen() function doesn't return a constant value, and it operates differently depending on compiler time. I've researched this situation, but I still don't understand it. Does anyone know?

    • @Selcuk._._
      @Selcuk._._ 5 месяцев назад

      for now i define constant like this
      #define MAX_LENGTH 20
      ...
      char car[] = "Supra Mark IV";
      char bestCar[MAX_LENGTH];
      ...
      and problem solved

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

    amazing teacher😍

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

    Make video for storage class mam.. Please

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

    Strlen()
    Strcpy(to,from)
    Strcat(text1,text2)
    Strcmp(text1,text2)
    Fgets(name,sizeof(name),stdin)

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

    Option (d) is correct.

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

    It was cute how you used "Pizza" for a food string, and then copied it into "bestFood".

  • @Sanidu123
    @Sanidu123 3 месяца назад

    Thanks a bunch 🙂

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

    #include
    #include
    int main() {
    char length1[45];
    char length2[45];
    printf("enter the character1:");
    fgets(length1,sizeof(length1),stdin);
    printf("enter the character2:");
    fgets(length2,sizeof(length2),stdin);
    int lengthofstring1=strlen(length1);
    int lengthofstring2=strlen(length2);
    if(lengthofstring1>lengthofstring2){
    printf("%s",length1);
    }
    if(lengthofstring1

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

    when I run the "strcat" function, "segmentation fault" this out put was shown
    #include
    #include
    int main(){
    char name1[]="hi";
    char name2[]="how are you";
    strcat(name1,name2);
    printf("%s",name1);
    return 0;
    }
    this is my code

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

    Why are the other videos private, please allow us to watch them.

  • @jordanholmes1366
    @jordanholmes1366 3 месяца назад

    #include
    #include
    int main(/*the answer is B strcat()*/){
    char str1[25], str2[25];
    printf("Type two strings: ");
    fgets(str1, sizeof(str1), stdin);
    fgets(str2, sizeof(str2), stdin);
    (strlen(str1) > strlen(str2)) ? printf("
    %s", str1) : printf("
    %s", str2);
    return 0;
    }

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

    Good video

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

    Thanks ma'am

  • @yogithabale
    @yogithabale 3 месяца назад

    opt B , strcat()

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

    Thank you so much 🤍

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

    Answer is B. strcat()

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

    #include
    #include
    int main()
    {
    int length1,length2;
    char text1[50];
    char text2[50];
    printf("enter the text1: ");
    fgets(text1,sizeof(text1),stdin);
    printf("enter the text2: ");
    fgets(text2,sizeof(text2),stdin);
    length1=strlen(text1);
    length2=strlen(text2);
    if(length1>length2)
    {
    printf("%s",text1);
    }
    else
    {
    printf("%s",text2);
    }
    }

  • @pawans.3766
    @pawans.3766 2 года назад

    #include
    #include
    int main()
    {
    char str1[10],str2[10];
    printf("enter a string");
    fgets(str1,sizeof(str1),stdin);
    printf("enter a string");
    fgets(str2,sizeof(str2),stdin);
    int result1 = strlen(str1); int result2 = strlen(str2);
    if(result1>result2){
    printf("str1 is big %s",str1);
    }
    else{
    printf("str2 is big %s",str2);
    }
    return 0;
    }

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

    good dmais

  • @koxygraphics8706
    @koxygraphics8706 2 года назад +3

    I’m here because of Alx

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

    The answer is B. strcat()

  • @PraveenPraveen-us3rp
    @PraveenPraveen-us3rp Год назад

    Options B

  • @lynne.5416
    @lynne.5416 Год назад +5

    #include
    #include
    int main()
    {
    char string1[100];
    char string2[100];
    printf("Enter first word: ");
    fgets(string1, sizeof(string1), stdin);
    printf("Enter second word: ");
    fgets(string2, sizeof(string2), stdin);
    int Leghth1= strlen(string1);
    int Leghth2= strlen(string2);
    if(Leghth1>Leghth2){
    printf("%s has a larger string", string1);
    }
    else if(Leghth2>Leghth1) { printf("%s has a larger string", string2);
    }
    else { printf("Both have the same leghth"); }
    return 0;
    }

  • @oissimouni7726
    @oissimouni7726 11 месяцев назад

    #include
    #include
    int main(){
    char text1[20];
    char text2[20];
    printf("Enter the first text: ");
    fgets(text1,sizeof(text1),stdin);
    printf("Enter the second text:");
    fgets(text2,sizeof(text2),stdin);
    int result1=strlen(text1);
    int result2=strlen(text2);
    if (result1>result2){
    printf("%s is the longer text",text1);
    }
    else{
    printf("%s is the longer text",text2);
    }
    return 0;
    }

  • @light-warrior
    @light-warrior 8 месяцев назад

    #include
    #include
    int main() {
    char string[20];
    printf("
    Enter your name: ");
    fgets(string, sizeof (string), stdin);
    printf("
    Lenghth: %zu", strlen(string));
    char string1[20];
    printf("
    Enter your name: ");
    fgets(string1, sizeof (string1), stdin);
    printf("
    Lenghth: %zu", strlen(string1));
    if (string > string1) {
    printf("
    Longer name: %s", string);
    } else {
    printf("
    Longer name: %s", string1);
    }
    return 0;
    }
    B is the correct option.

  • @mokka_comedy
    @mokka_comedy 5 месяцев назад

    Now string functions are not working in the programiz complier....................

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

    Answer : B

  • @bbek300
    @bbek300 6 месяцев назад

    #include
    #include
    int main() {
    char word1[20];
    char word2[20];
    printf("Enter word1: ");
    fgets(word1, sizeof(word1), stdin);
    printf("Enter word2: ");
    fgets(word2, sizeof(word2), stdin);
    int L1 = strlen(word1);
    int L2 = strlen(word2);
    if(L1 > L2){
    printf("%s",word1);
    }
    else if(L2 > L1){
    printf("%s",word2);
    }
    else{
    printf("Both are equal");
    }
    return 0;
    }

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

    Answer is B

  • @JeongWoonKim-i4j
    @JeongWoonKim-i4j Год назад

    #include
    #include
    int main() {
    char str1[50];
    char str2[50];
    printf("Enter the fisrt string: ");
    fgets(str1, sizeof(str1), stdin);
    printf("Enter the second string: ");
    fgets(str2, sizeof(str2), stdin);
    if(strlen(str1) > strlen(str2)) {
    printf("%s", str1);
    }
    else if(strlen(str1) < strlen(str2)) {
    printf("%s", str2);
    }
    else {
    printf("None");
    }
    return 0;
    }

  • @hunter9544
    @hunter9544 6 месяцев назад

    // Online C compiler to run C program online
    #include
    #include
    int main() {
    // Write C code here
    char text1[100];
    char text2[100];
    int lengthoftext1;
    int lengthoftext2;
    printf("Enter text 1: ");
    fgets(text1, sizeof(text1), stdin);
    { printf("Enter text 2: ");
    fgets(text2, sizeof(text2),stdin);
    lengthoftext1=strlen(text1);
    lengthoftext2=strlen(text2);
    if (lengthoftext1 > lengthoftext2)
    { printf("%s", text1); }
    else if (lengthoftext2 > lengthoftext1) {
    printf("%s", text2);
    }
    else
    printf("Both: %s and: %s are the same length", text1, text2);
    }


    return 0;
    }
    Arise

  • @vintrixtergunot8064
    @vintrixtergunot8064 3 месяца назад

    #include
    #include
    int main() {
    char str1 [20];
    char str2 [20];
    int lengthStr1;
    int lengthStr2;
    printf("String 1: ");
    fgets (str1, sizeof (str1), stdin);
    printf("String 2: ");
    fgets (str2, sizeof (str2), stdin);
    lengthStr1 = strlen (str1);
    lengthStr2 = strlen (str2);
    if (lengthStr1 > lengthStr2){
    printf ("%s", str1);
    }
    else if (lengthStr1 < lengthStr2){
    printf ("%s", str2);
    }

    return 0;
    }

  • @HoangDo-yv1yw
    @HoangDo-yv1yw Год назад

    👍👍

  • @moazriad6582
    @moazriad6582 5 месяцев назад +1

    char str9[50];
    char str10[50];
    printf("ENTER NAME:");
    fgets(str9,sizeof(str9),stdin);
    printf("ENTER NAME:");
    fgets(str10,sizeof(str10),stdin);
    int m=strlen(str9);
    printf("%d
    ",m);
    int z=strlen(str10);
    printf("%d
    ",z);
    if(m>z)
    printf("%s",str9);
    if(z>m)
    printf("%s",str10);

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

    #include
    #include
    int main() {
    char text1[15];
    char text2[15];
    int lenght1;
    int lenght2;
    printf("Enter text1: ");
    fgets(text1, sizeof(text1), stdin);
    printf("Enter text2: ");
    fgets(text2, sizeof(text2), stdin);
    lenght1 = strlen(text1);
    lenght2 = strlen(text2);
    if (lenght1 > lenght2)
    {
    printf("%s", text1);
    }
    else if (lenght2 == lenght1)
    {
    printf("the same lenght");
    }
    else
    printf("%s", text2);
    return 0;
    }

  • @anesp.a913
    @anesp.a913 2 года назад

    strcat(first string,second string);

  • @Azizam-j3c
    @Azizam-j3c Год назад

    //Solution:
    #include
    #include
    int main() {
    char str1[50];
    char str2[50];
    printf("Enter the first String: ");
    fgets(str1, 50, stdin);
    printf("Enter the second String: ");
    fgets(str2, 50, stdin);
    char result[(strlen(str1) > strlen(str2)) ? strlen(str1) : strlen(str2)];
    (strlen(str1) > strlen(str2)) ? strcpy(result, str1) : strcpy(result, str2);
    printf("%s", result);
    return 0;
    }

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

    The answer is C
    By the way all of the answers are the letter C because we are working in C programming language

  • @formodapk
    @formodapk 7 дней назад

    #programiz

  • @streamvision145
    @streamvision145 5 месяцев назад +1

    #include
    #include
    int main() {
    char str1[30];
    char str2[30];
    printf("-----------String Comparison-----------

    ");
    printf("Enter string 1: ");
    fgets(str1,sizeof(str1),stdin);
    printf("Enter string 2: ");
    fgets(str2,sizeof(str2),stdin);
    int diff = strlen(str1) - strlen(str2);
    if(diff > 0){
    printf("
    The larger string is %s.",str1);
    } else if(diff < 0){
    printf("
    The larger string is %s.",str2);
    }else{
    printf("
    Both are of the same length.");
    }
    return 0;
    }

  • @ixa-i
    @ixa-i 10 месяцев назад

    #include
    #include
    #include
    int main() {
    char txt1[50];
    char txt2[50];
    printf("Enter 2 strings: ");
    fgets(txt1, sizeof(txt1), stdin);
    fgets(txt2, sizeof(txt2), stdin);
    strlen(txt1);
    strlen(txt2);
    if(strlen(txt1)>strlen(txt2)){
    printf("%s",txt1);
    }
    else{
    printf("%s",txt2);
    }
    return 0;
    }

  • @fighterboy6577
    @fighterboy6577 2 года назад +3

    b

  • @Clog17
    @Clog17 4 месяца назад

    #include
    #include
    #define size 100
    int main()
    {
    char str[size];
    char str2[size];
    printf("please enter a name: ");
    fgets(str, sizeof(str),stdin);
    printf("please enter a surname: ");
    fgets(str2, sizeof(str2),stdin);
    if (strlen(str) > strlen(str2)){
    printf ("%s", str);
    }
    else{
    printf("%s", str2);
    }
    return 0;
    }

  • @AkunemeMighty
    @AkunemeMighty Год назад +1

    #include
    #include
    int main() {
    // Create a program to compare two strings and prints the larger strings.
    // * Get two strings input from the user using fgets().
    // * compare the length of both strings using strlen().
    // * Print the larger string.
    char name1[20];
    char name2[20];
    printf("Enter first full name: ");
    fgets(name1, sizeof(name1), stdin);
    printf("Enter second full name: ");
    fgets(name2, sizeof(name2), stdin);
    if (strlen(name1) < strlen(name2))
    {
    printf("%s", name2);
    }
    else {
    printf("%s", name1);
    }
    }

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

    i love you padma manandhar

  • @sandeepvarma8453
    @sandeepvarma8453 6 месяцев назад

    b.strcat( )

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

    İt is Zero not Cero

  • @dhairyapatel9963
    @dhairyapatel9963 9 месяцев назад

    B

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

    B. strcat()

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

    // Online C compiler to run C program online
    #include
    #include
    int main() {
    char text1[100], text2[100];
    printf("Enter String 1 : ");
    fgets(text1, sizeof(text1), stdin);
    printf("Enter String 2 : ");
    fgets(text2, sizeof(text2), stdin);
    int len1 = strlen(text1);
    int len2 = strlen(text2);
    if (len1 > len2)
    printf("%s is Greater", text1);
    else if (len2 > len1)
    printf("%s is Greater", text2);
    else
    printf("Both are same");
    return 0;
    }

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

    strat()

  • @muhammadrizobegijonov4002
    @muhammadrizobegijonov4002 5 месяцев назад

    0

  • @Profession_marketting
    @Profession_marketting 11 месяцев назад

    Wo

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

    quiz anwer :b

  • @bryanbalantes6486
    @bryanbalantes6486 Год назад +1

    /*
    Create a program to compare two strings and
    print the larger strings.
    * Get two string input from the user using
    fgets()
    * Compare the length of both the strings using
    strlen()
    * Print the larger string
    */
    #include
    #include
    char compare(char firstWord[100], char secondWord[100]);
    int main(){
    char stringInput1[100];
    char stringInput2[100];

    printf("Enter a first word: ");
    fgets(stringInput1, sizeof stringInput1, stdin);
    printf("Enter a second word: ");
    fgets(stringInput2, sizeof stringInput2, stdin);

    compare(stringInput1, stringInput2);
    return 0;
    }
    char compare(char firstWord[100], char secondWord[100]){
    int lengthText1 = strlen(firstWord);
    int lengthText2 = strlen(secondWord);
    if (lengthText1 > lengthText2){
    return printf("%s ", firstWord);
    }
    else if (lengthText1 < lengthText2){
    return printf("%s ", secondWord);
    }
    else{
    return printf("%s", strcat(firstWord, secondWord) );
    }

    }

  • @Akhil-hd8qe
    @Akhil-hd8qe 5 месяцев назад

    Akka you are so beautiful

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

    this is my code:
    #include
    #include
    int main(){
    char text1[100];
    char text2[100];
    printf("Enter first string: ");
    gets(text1);
    printf("
    Enter second string: ");
    gets(text2);
    if(strlen(text1) > strlen(text2)){
    printf("
    First string is longer which is: %s",text1);
    }else
    printf("
    Second string is longer which is: %s",text2);
    return 0;
    }

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

    #include
    #include
    int main()
    {
    char game[20];
    char match[20];
    int length_of_game;
    int length_of_match;
    printf("ENTER THE GAME: ");
    fgets(game, sizeof(game), stdin);
    printf("ENTER THE MATCH : ");
    fgets(match, sizeof(match), stdin);
    length_of_game = strlen(game);
    length_of_match = strlen(match);
    if(length_of_game> length_of_match){
    printf("%s", game);
    }
    if(length_of_game==length_of_match){
    printf("strings have the same length");
    }
    else{
    printf("%s", match);
    }
    return 0;
    }

  • @jmarkyt5453
    @jmarkyt5453 Год назад +1

    #include
    #include
    #include
    #include
    int main()
    {
    char name[24];
    char name1[24];
    printf("Enter your name:");
    fgets(name, sizeof(name), stdin);
    printf("Enter your friends name:");
    fgets(name1, sizeof(name1), stdin);
    printf("
    The Length of %s is : %zu", name, strlen(name));
    printf("
    And the Length of %s is: %zu

    ", name1, strlen(name1));
    printf("%s:%zu
    ", name, strlen(name));
    printf("%s:%zu", name1, strlen(name1));

    return 0;
    }

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

    // Task programme 😀😀
    #include
    #define n 100
    int main(){
    char str1[n];
    char str2[n];
    printf("enter the first string:");
    gets(str1);
    printf("enter the second string:");
    gets(str2);
    int result1=strlen(str1);
    int result2=strlen(str2);
    printf("%d
    ",result1);
    printf("%d
    ",result2);
    if(result1>result2)
    {
    printf(" Got it str1 is the longer string.");
    }
    else{
    printf(" Got it str2 is the longer string.");
    }
    }

  • @1NazareeM618
    @1NazareeM618 Год назад

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

    #include
    #include
    #include
    int main()
    {
    char a[20]="Anjeep Shrestha";
    char b[30]=" is a good boy.";
    // for finding the length
    printf("The length of string a is %zu",strlen(a));
    // for string copy
    char c[strlen(a)];
    strcpy(c,a);
    printf("
    %s",c);
    // for string concatenation
    strcat(a,b);
    printf("
    The concatenated string is %s",a);
    // for string compare
    char d[10]="anjeep";
    char e[10]="anjeep";
    char f[10]="shrestha";
    printf("
    The value for d and e compare is %d",strcmp(d,e));
    printf("
    The value for e and f compare is %d",strcmp(e,f));
    printf("
    The value for f and e compare is %d",strcmp(f,e));
    }

  • @missserwaa_
    @missserwaa_ 11 месяцев назад

    #include
    #include
    int main()
    {
    char name[30];
    char hometown[30];
    printf("Enter your name: ");
    fgets(name, sizeof(name), stdin);
    printf("Your name is: %s", name);
    printf("Enter hometown: ");
    fgets(hometown, sizeof(hometown), stdin);
    printf("Your hometown is: %s", hometown);
    printf("
    length of name: %zu", strlen(name));
    printf("
    length of hometown: %zu", strlen(hometown));
    if(strlen(name) > strlen(hometown)) {
    printf("
    %s", name);
    } else {
    printf("
    %s", hometown);
    }
    return 0;
    }

  • @freehug071
    @freehug071 Год назад +1

    #include
    #include
    int main(void)
    {
    char text1[45];
    char text2[45];
    printf("please Enter your name:");
    fgets(text1, sizeof(text2), stdin);
    printf("%s", text1);
    printf("please Enter your school:");
    fgets(text2, sizeof(text2), stdin);
    printf("%s
    ", text2);
    if(strlen(text1) > strlen(text2)){
    printf("leng of text1 is %zu", strlen(text1));
    }
    if(strlen(text2) > strlen(text1)){
    printf("leng of text2 is %zu", strlen(text2));
    }
    else{
    printf("the leng of two string is equal");
    }
    return 0;
    }

  • @onic9623
    @onic9623 Год назад +1

    Option B : strcat()
    -----------------------------------------------------------------------------
    #include
    #include
    int main()
    {
    char text1[100], text2[100];
    while (1)
    {
    printf("Enter A Name : ");
    fgets(text1, sizeof(text1), stdin);
    printf("Enter Another Name : ");
    fgets(text2, sizeof(text2), stdin);
    if (strlen(text1) > strlen(text2))
    {
    printf("%s", text1);
    }
    else if (strlen(text1) < strlen(text2))
    {
    printf("%s", text2);
    }
    else
    {
    printf("Both Are Of Equal Lenghth");
    }
    }
    return 0;
    }

  • @daireosullivan1193
    @daireosullivan1193 6 месяцев назад

    #include
    #include
    #include
    #include
    #include
    int main() {
    char text1[200];
    char text2[200];
    printf("Enter a text: ");
    fgets(text1, sizeof(text1), stdin);
    printf("Enter another text: ");
    fgets(text2, sizeof(text2), stdin);
    if (strlen(text1) > strlen(text2)) {
    printf("%s", text1);
    }
    else if (strlen(text1) == (strlen(text2))) {
    printf("Equal Strings");
    }
    else {
    printf("%s", text2);
    }

    return 0;
    }

  • @PedroLopes-k5f
    @PedroLopes-k5f Год назад

    #include
    #include
    int main (){
    char text1[40];
    char text2[40];

    int lenght1;
    int lenght2;

    printf("Digite uma palavra: ");
    scanf("%s", &text1);



    printf("Digite uma palavra: ");
    scanf("%s", &text2);

    fgets(text1, sizeof(text1), stdin);
    lenght1 = strlen(text1);

    fgets(text2, sizeof(text2), stdin);
    lenght1 = strlen(text2);

    strcmp(text1, text2);

    if (lenght1 > lenght2){

    printf ("%s ", text1);
    }

    else if (lenght2 > lenght1){

    printf(" %s", text2);
    }
    else{

    printf("Length of text2 is equal to text1");
    }

    return 0;

    }

  • @TheHeraldOfSpring
    @TheHeraldOfSpring 2 месяца назад

    #include
    #include
    int main(){
    char userString1[40], userString2[40];
    printf("Enter your first statement: ");
    fgets(userString1, 40, stdin);
    printf("Enter your second statement: ");
    fgets(userString2, 40, stdin);

    int strSize1 = strlen(userString1);
    int strSize2 = strlen(userString2);
    printf("
    Now we will print the biggest statement...

    ");
    if(strSize1 > strSize2){
    printf("The winner statement is:
    %s", userString1);
    }
    else if(strSize2 > strSize1){
    printf("The winner statement is:
    %s", userString2);
    }
    else{
    printf("The friendship has won:

    %s
    %s", userString1, userString2);
    }
    return 0;
    }

  • @Isasseguya
    @Isasseguya 10 месяцев назад

    #include
    #include
    #include
    int main() {
    char txt1[50];
    char txt2[50];
    printf("Enter 2 strings: ");
    fgets(txt1, sizeof(txt1), stdin);
    fgets(txt2, sizeof(txt2), stdin);
    strlen(txt1);
    strlen(txt2);
    if(strlen(txt1)>strlen(txt2)){
    printf("%s",txt1);
    }
    else{
    printf("%s",txt2);
    }
    return 0;
    }