#22 C String Functions | C Programming For Beginners

preview_player
Показать описание
#22 C String Functions | C Programming For Beginners

Previously, we learned about one of the frequently used concepts in programming: Strings, And came to know why they are used and how to use them in our programs.

C supports a large number of string handling functions in the standard library " string.h". Today, we will learn to manipulate various C string functions that are readily available for use. More specifically, we will focus on the 4 most important string functions that are used to perform different operations on strings.

~
Resources:

Timestamps:
00:00 Start
00:28 C Strings
01:33 strlen() function
03:20 strcpy() function
05:02 strcat() function
06:32 strcmp() function
08:48 Programming Task
09:17 Quiz
~

Revise your learning using our C App

Find Programiz elsewhere:

#programiz #cprogramming #stringfunctions #learnc #strings #function #libraryfunction #cstring #stringsinc
Рекомендации по теме
Комментарии
Автор

🔥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!

programizstudios
Автор

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.

mmhbmqh
Автор

/*Create a Program to compare two strings and print the larger string.*/
#include <stdio.h>
#include <string.h>
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;
}

RalphAdrianePDilao
Автор

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

alv
Автор

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

jingsnline
Автор

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

pokhto_k_programming
Автор

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

nahomiperezflores
Автор

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

ntnmfbu
Автор

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

eszterannaimre
Автор

great video!
for the quiz to join two together is the strcat() function and this is the program to print the larger input:
#include <stdio.h>
#include <string.h>

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);


printf(word2);
}else{
printf(word1);
}
return 0;
}

stealthy_doctor
Автор

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

erlnd
Автор

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

naiduyt
Автор

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

betzc
Автор

//Incredibly secure program, which compares string lenghts:
//I remembered video #10, are you proud of me? XD

#include <stdio.h>
#include <string.h>
int main()
{
printf("Enter string one: ");
char string1[50];
gets(string1);

printf("Enter string two: ");
char string2[50];
gets(string2);

printf("\nThe longer string is: ");
(strlen(string1)) > strlen(string2) ? printf(string1) : printf(string2);

return 0;
}

laurenzwegler
Автор

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

errorhostnotfound
Автор

5:53 why text1 ?
pls can anyone explain

onic
Автор

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 <stdio.h>

int main() {
char string1[20];
printf ("Enter string 1:");
fgets(string1, sizeof(string1), stdin);
printf ("\n Length: %zu", strlen(string1));

char string2[20];
printf ("\nEnter string 2:");
fgets(string2, sizeof(string2), stdin);
printf ("\n Length: %zu", strlen(string2));


if (strlen(string1)> strlen(string2)){
printf ("\nSting 1 is bigger");
}
else if (strlen(string2) > strlen(string1)){
printf("\nString 2 is bigger");
}
else {
printf ("\nSame length");
}


return 0;
}

arianas
Автор

Make video for storage class mam.. Please

thilagawathis
Автор

The answer is option B mam thank you
😊😊😊

mkozfnc
Автор

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

onomemafuru