include<stdio.h>
int main()
{
int month;
scanf("%d", &month);
char a[12][10] = {
//这里是12是因为结尾的'\0',11的话会报错
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
printf("%s", a[month-1]);
//如果打印a[month-1][10]只会打印一个字符
return 0;
}
//int *const p1 = &i; 指针不能被修改
//int const *p2 = &i; 通过指针不可修改
//const int *p3 = &i; 通过指针不可修改
#include<stdio.h>
int main()
{
int ch;
while ((ch = getchar()) != EOF) putchar(ch);
return 0;
//getchar、putchar返回int
}
/*
string.h:
strlen: strlen(const char*s) 返回长度,
sizeof带\0,值+1
strcmp: (const char *s1, const char *s2)
strcpy:(目的,源),return 目的
strncpy:控制复制个数
strncpy(array,&arr[a],b);
strcat:(const char *des, const char *source),接在des的末尾
strstr:寻找字符串
strcasestr:忽略大小写寻找字符串
strchr:找字符第一个出现的位置
char *strchr(const char*s,int c);
char *strrchr(const char*s ,int c);右边开始找
*/
#include<stdio.h>
int size_ofs(const char *s)
{
int cnt = 0;
int idx = 0;
while (s[idx] != '\0') {
idx++; cnt++;
}
return cnt;
}
int main()
{
char s[] = "Hello World";
printf("%d\n", sizeof(s)); // 12
printf("%d\n", strlen(s)); // 11
printf("%d\n", size_ofs(s)); // 11
return 0;
}
#include<stdio.h
//输出strchr以外的字符串
int main()
{
char s[] = "hello";
char* p = strchr(s, 'l');
char c = *p;
*p = '\0';
char* t = (char*)malloc(strlen(s) + 1);
strcpy(t, s);
printf("%s\n", t);
*p = c;
free(t);
return 0;
}