1.指针的基本使用
#include<stdio.h>
#include<string.h>
void Test1()
{
char strArr[5][10]={"qwer","ty","uiopasd","fghjkl","zxc"};
int i,j;
char strTemp[10]={"\0"};
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
if(strlen(strArr[j])>strlen(strArr[j+1]))
{
strcpy(strTemp,strArr[j]);
strcpy(strArr[j],strArr[j+1]);
strcpy(strArr[j+1],strTemp);
}
}
}
for(i=0;i<5;i++)
{
printf("%c",*(strArr[i]+2));
}
}
//字符替换
void replace()
{
char arr[11]={"attEESeTTa"};
int i,n=0;
for(i=0;i<strlen(arr);i++)
{
if(arr[i]=='t')
{
arr[i]='e';
n++;
}else if(arr[i]=='T')
{
arr[i]='E';
n++;
}else if(arr[i]=='e')
{
arr[i]='t';
n++;
}else if(arr[i]=='E')
{
arr[i]='T';
n++;
}
}
printf("\n替换为:\n");
puts(arr);
printf("替换的个数为:%d\n",n);
}
void Test3()
{
char strArr[7][10]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"," Sunday"};
int i;
int week;
while(scanf("%d",&week))
{
if(week>0&&week<8)
{
printf("%s\n",strArr[week-1]);
}else
{
printf("输入不正确,请重新输入\n");
}
}
}
void main()
{
Test1();
replace();
Test3();
}