练习9-1
/*---输出字符数组char str[] = "ABC\0DEF"---*/
#include <stdio.h>
int main(void)
{
char str[] = "ABC\0DEF";
printf("字符串str为\"%s\"。\n", str);
return 0;
}
练习9-2
/*---让该初始化赋值得到的字符串s变成空字符串:char s[] = "ABC"---*/
#include <stdio.h>
int main (void)
{
char s[] = "ABC";
s[0] = '\0';
printf("字符串s为:%s",s);
return 0;
}
练习9-3
/*对代码清单9-7进行改写*/
#include <stdio.h>
#define NUMBER 5
int main(void)
{
int i;
char s[NUMBER][128];
for (i = 0; i < NUMBER; i++) {
printf("s[%d]:", i);
scanf("%s", s[i]);
if (strcmp(s[i], "$$$$$") == 0)
break;
}
for(i = 0; i < NUMBER; i++){
if (strcmp(s[i], "$$$$$") == 0)
break;
printf("s[%d] = \"%s\"\n", i, s[i]);
}
return 0;
}
练习9-4
/*---编写一个函数,使字符串s为空字符串。---*/
#include <stdio.h>
void null_string(char s[]){
s[0] = '\0';