Podcast
Questions and Answers
What does the function strcat(dest, src)
do?
What does the function strcat(dest, src)
do?
What is the purpose of the strupr(str)
function?
What is the purpose of the strupr(str)
function?
Which function is used to compare two strings?
Which function is used to compare two strings?
What is the result of the code sprintf(str, "Hello, %s!", "World")
?
What is the result of the code sprintf(str, "Hello, %s!", "World")
?
Signup and view all the answers
What is the purpose of the strrev(str)
function?
What is the purpose of the strrev(str)
function?
Signup and view all the answers
Study Notes
String Functions
- Library: ``
-
Functions:
-
strlen(str)
: returns the length of the string -
strcpy(dest, src)
: copies the stringsrc
todest
-
strcat(dest, src)
: concatenatessrc
to the end ofdest
-
strcmp(str1, str2)
: compares two strings, returns 0 if equal -
strchr(str, c)
: returns a pointer to the first occurrence of characterc
instr
-
strstr(str1, str2)
: returns a pointer to the first occurrence ofstr2
instr1
-
String Manipulation
-
Functions:
-
strupr(str)
: converts a string to uppercase -
strlwr(str)
: converts a string to lowercase -
strupr(str)
: converts the first character of a string to uppercase -
strrev(str)
: reverses a string
-
- Note: These functions are not part of the standard `` library, but are commonly used in string manipulation.
String Concatenation
-
Using
strcat()
:-
strcat(str1, str2)
: concatenatesstr2
to the end ofstr1
- Example:
strcat("Hello, ", "World!")
results in "Hello, World!"
-
-
Using array indexing:
- Example:
char str[20]; strcpy(str, "Hello"); str[5] = ','; strcat(str, " World!");
results in "Hello, World!"
- Example:
-
Using
sprintf()
:-
sprintf(str, "format string", arguments)
: formats a string using the format string and arguments - Example:
sprintf(str, "Hello, %s!", "World")
results in "Hello, World!"
-
String Functions
-
strlen(str)
returns the length of the string. -
strcpy(dest, src)
copies the stringsrc
todest
. -
strcat(dest, src)
concatenatessrc
to the end ofdest
. -
strcmp(str1, str2)
compares two strings and returns 0 if they are equal. -
strchr(str, c)
returns a pointer to the first occurrence of characterc
instr
. -
strstr(str1, str2)
returns a pointer to the first occurrence ofstr2
instr1
.
String Manipulation
-
strupr(str)
converts a string to uppercase. -
strlwr(str)
converts a string to lowercase. -
strupr(str)
converts the first character of a string to uppercase. -
strrev(str)
reverses a string. - Note: These functions are not part of the standard library, but are commonly used in string manipulation.
String Concatenation
-
strcat(str1, str2)
concatenatesstr2
to the end ofstr1
. - Example:
strcat("Hello, ", "World!")
results in "Hello, World!". - Concatenation using array indexing: Example:
char str; strcpy(str, "Hello"); str[5] = ','; strcat(str, " World!");
results in "Hello, World!". -
sprintf(str, "format string", arguments)
formats a string using the format string and arguments. - Example:
sprintf(str, "Hello, %s!", "World")
results in "Hello, World!".
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
This quiz covers the string functions in C programming, including strlen, strcpy, strcat, strcmp, strchr, and strstr. Test your knowledge of string manipulation in C.