Check if the string is empty in C language.

In the C language, it is possible to determine if a string is empty by checking its length. If the length of the string is 0, then it is considered empty.

Below is an example code.

#include <stdio.h>
#include <string.h>

int main() {
    char str[100];
    printf("请输入一个字符串:");
    scanf("%s", str);

    if (strlen(str) == 0) {
        printf("字符串为空\n");
    } else {
        printf("字符串不为空\n");
    }

    return 0;
}

In the above example code, the user input string is first read with the scanf function and stored in the str array. Then, the strlen function is used to determine the length of the string, and it is determined whether the string is empty by checking if the length is 0.

广告
Closing in 10 seconds
bannerAds