Complete the code to copy the string from source to destination using a standard library function.
#include <string.h> #include <stdio.h> int main() { char source[] = "Hello"; char destination[10]; [1](destination, source); printf("%s", destination); return 0; }
The strcpy function copies the string from the source to the destination.
Complete the code to find the length of the string using a standard library function.
#include <string.h> #include <stdio.h> int main() { char str[] = "Hello, world!"; int length = [1](str); printf("Length: %d", length); return 0; }
The strlen function returns the length of the string excluding the null character.
Fix the error in the code to compare two strings correctly using a standard library function.
#include <string.h> #include <stdio.h> int main() { char str1[] = "apple"; char str2[] = "apple"; if ([1](str1, str2) == 0) { printf("Strings are equal\n"); } else { printf("Strings are different\n"); } return 0; }
The strcmp function compares two strings and returns 0 if they are equal.
Fill both blanks to concatenate two strings safely using a standard library function.
#include <string.h> #include <stdio.h> int main() { char str1[20] = "Hello, "; char str2[] = "World!"; [1](str1, str2, [2]); printf("%s", str1); return 0; }
The strncat function concatenates strings safely by specifying the maximum number of characters to append. The size calculation ensures no buffer overflow.
Fill all three blanks to create a substring by copying part of a string using standard library functions.
#include <string.h> #include <stdio.h> int main() { char source[] = "Programming"; char substring[10]; strncpy(substring, source + [1], [2]); substring[[3]] = '\0'; printf("%s", substring); return 0; }
The code copies 6 characters starting from index 3 of the source string. Then it adds a null character at index 6 to end the substring properly.