Finding C programming hard? We’ve got you! 🚀Get 60% off on Programiz PRO Lifetime Plan this Black Friday-pay once for skills that last forever. Don’t miss out, it’s a limited-time offer! 👉Grab your discount now: bit.ly/blkfriday-24-yt
@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; }
@josephnieves81753 ай бұрын
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 Жыл бұрын
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.
@RalphAdrianePDilao2 жыл бұрын
/*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 Жыл бұрын
❤
@qarikhalidwaheed1643 Жыл бұрын
@@AFCOE It works perfectly! I Copied it into the Programiz compiler and it works perfectly! 👍👌
@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ы Жыл бұрын
аа
@9189030217 ай бұрын
@@ВладимирСоколовский-щ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_programming2 жыл бұрын
"Googling things is most the important skill in programing" 👍💯
@erl2nd2 жыл бұрын
Thank you so much, Well done and much appreciated! ☺️ Quiz answer is: B
@eszterannaimre711 Жыл бұрын
Thank you! You are saving me from failing my course!
@segunomotosho1131 Жыл бұрын
#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; }
@jings0nline4 ай бұрын
Loved watching your c programming series, come back with such contents again madam.
@alv19472 жыл бұрын
No word to say how awesome is your work. thank you Programiz team. Simply you rock !!
@MagaScampini7 ай бұрын
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.
@hrkhrld5 ай бұрын
i got segmentation error idk why
@arianas78662 жыл бұрын
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-nt4nm4fb3u10 ай бұрын
As always great explanation. Thank you Programiz for this amazing Tutorial series!!!!!!!!!!! I am really enjoying C programming with these tutorial videos!
@nahomiperezflores77272 жыл бұрын
I love your videos, I understand them easily. Can you explain pointers? Pleaseee
@jordanholmes13665 ай бұрын
#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; }
@stealthy_doctor5 ай бұрын
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)
@laurenzwegler71414 ай бұрын
//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; }
@naiduyt33502 жыл бұрын
Please do atleast one video daily, can't wait !
@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
@betzc9433 Жыл бұрын
I was feeling sad because I was having problems, but now everything is making sense!! Thank youuu!
#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; }
@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); } }
@onic9623 Жыл бұрын
5:53 why text1 ? pls can anyone explain
@Onceupon5302 Жыл бұрын
Same doubt😢
@lynne.54162 жыл бұрын
#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; }
@light-warrior10 ай бұрын
#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.
#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; }
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_s312 жыл бұрын
Use #include header file
@akntmzjtj2 жыл бұрын
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.
@yogithabale4 ай бұрын
mam , strcat type function is showing error - segmentation fault
@programizstudios2 жыл бұрын
Q. Which of the following functions is used to join two strings? a. strjoin() b. strcat() c. join() d. cat()
#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); } }
@thilagawathis39972 жыл бұрын
Say every line meaning mam... It will help to crack interview..
@onomemafuru94962 жыл бұрын
For the string length calculation of "C programming" is it the white space between C and programming that is counted or the terminal \0?
@AbhiramDeshpande-fe1vi Жыл бұрын
its the space
@AbhiramDeshpande-fe1vi Жыл бұрын
I too got a doubt but later i tested it ....
@DCSDilshadAhmad Жыл бұрын
Option (d) is correct.
@b7sh_b7sh Жыл бұрын
amazing teacher😍
@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; }
@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; }
@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; }
@Sanidu1234 ай бұрын
Thanks a bunch 🙂
@streamvision1456 ай бұрын
#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; }
@Clog176 ай бұрын
#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; }
@koxygraphics87062 жыл бұрын
I’m here because of Alx
@thilagawathis39972 жыл бұрын
Make video for storage class mam.. Please
@Peter_1986 Жыл бұрын
It was cute how you used "Pizza" for a food string, and then copied it into "bestFood".
@_txt_7398 Жыл бұрын
Thank you so much 🤍
@avdeshsingh001 Жыл бұрын
Thanks ma'am
@nagashreenb476318 күн бұрын
void main() { char str1[20],str2[20]; printf("Enter first str1:"); fgets(str1,sizeof(str1),stdin); printf("Enter the second Str2:"); fgets(str2,sizeof(str2),stdin); int sizeofstr1=strlen(str1); printf("Size of the str1 is :%d ",sizeofstr1); int sizeofstr2=strlen(str2); printf("Size of the str2 is :%d ",sizeofstr2); if(sizeofstr1>sizeofstr2) printf("the largest str is str1:%s ",str1); else if(sizeofstr1
@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
@inhhuynhcong5009 Жыл бұрын
I think c programmiz gets a bug so you cannot run this code
@mohamedhajith965 Жыл бұрын
Ok thank you
@kevinolvera8124 Жыл бұрын
Good video
@yogithabale4 ай бұрын
opt B , strcat()
@bullshit48525 күн бұрын
The Answer is B. strcat().
@formodapkАй бұрын
#programiz
@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
@learnathingthroughouttheda34642 жыл бұрын
Why are the other videos private, please allow us to watch them.
@albertamenyah3019 Жыл бұрын
The answer is B. strcat()
@mdarifulislamsiam63256 күн бұрын
strcat is not clear why we have used text 1 in printf why not text 2
@QingqiYang Жыл бұрын
Why does my strcmp function output -1 when it supposed to output -4?
@Selcuk._._7 ай бұрын
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._._7 ай бұрын
for now i define constant like this #define MAX_LENGTH 20 ... char car[] = "Supra Mark IV"; char bestCar[MAX_LENGTH]; ... and problem solved
@PraveenPraveen-us3rp Жыл бұрын
Options B
@thiagaodavez5465 Жыл бұрын
good dmais
@qarikhalidwaheed1643 Жыл бұрын
The answer is C By the way all of the answers are the letter C because we are working in C programming language
@fighterboy65772 жыл бұрын
b
@shriyanshgupta99512 жыл бұрын
// 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; }
@anesp.a9132 жыл бұрын
strcat(first string,second string);
@HoangDo-yv1yw Жыл бұрын
👍👍
@keshavdixit082 жыл бұрын
Answer : B
@sibonginkosiphiri6269 Жыл бұрын
Answer is B
@freehug071 Жыл бұрын
#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; }
@mokka_comedy6 ай бұрын
Now string functions are not working in the programiz complier....................
@missserwaa_ Жыл бұрын
#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; }
@bryanbalantes6486 Жыл бұрын
/* 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) ); } }
@sandeepvarma84537 ай бұрын
b.strcat( )
@mofemoluwasiogunrinde48912 жыл бұрын
B. strcat()
@mohammednoorullahkhan Жыл бұрын
i love you padma manandhar
@aritradey71892 жыл бұрын
// 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."); } }
@amirfoo65652 жыл бұрын
B
@chrisoigo85982 жыл бұрын
#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; }
@herkesebolsanshahaha4229 Жыл бұрын
İt is Zero not Cero
@Amirak254 Жыл бұрын
strat()
@Profession_marketting Жыл бұрын
Wo
@muhammadrizobegijonov40027 ай бұрын
0
@xxxegster6527 Жыл бұрын
quiz anwer :b
@Akhil-hd8qe6 ай бұрын
Akka you are so beautiful
@hunter95447 ай бұрын
// 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
@anjeepshrestha61772 жыл бұрын
#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)); }