c语言 9-4

1、

#include <stdio.h>

void null_string(char x[])
{
    x[0] = ''; 
}

int main(void)
{
    char str[128];
    printf("str: "); scanf("%s", str);
    
    printf("begin: %s 
", str);
    
    null_string(str);
    
    printf("end: %s 
", str);
    
    return 0;
}

2、

#include <stdio.h>

void null_test(char x[])
{
    int len = 0;
    while(x[len])
        len++;
    int i;
    if(len > 0)
    {
        for(i = 0; i < len; i++)
        {
            x[i] = '';
        }
    }
}

int main(void)
{
    char str[1000];
    printf("str: "); scanf("%s", str);
    
    printf("begin: %s
", str);
    null_test(str);
    printf("end: %s
", str);
    
    return 0;
}

3、

#include <stdio.h>

void null(char x[])
{
    *x = 0;
}

int main(void)
{
    char str[100];
    printf("str: "); scanf("%s", str);
    
    printf("begin: %s 
", str);
    null(str);
    printf("end: %s 
", str);
    
    return 0;
}

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14810804.html