今天学习了关于指针方面的知识,老师说过是难点,希望能尽快熟练运用!
作业1
#include<stdio.h>
#include<string.h>
int main()
{
//char *p[5];
char ss[10]={"\0"};
char s[5][10]={"ertt","dwnns","ej","nenwbrt","abc"};
int i,j;
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
if(strlen(s[i])>strlen(s[i+1]))
{
strcpy(ss,s[i]);
strcpy(s[i],s[i+1]);
strcpy(s[i+1],ss);
}
}
}
strcpy(ss,"\0");
for(i=0;i<5;i++)
{
if((*(s[i]+2))!='\0')
{
ss[i]=*(s[i]+2);
}
else
{
ss[i]=' ';
}
}
puts(ss);
for(i=0;i<5;i++)
{
puts(s[i]);
}
}
作业2
#include<stdio.h>
int replace(char *p);
int main()
{
int b;
char s[20]={"\0"};
gets(s);
b=replace(s);
puts(s);
printf("替换的字符个数为:%d\n",b);
}
int replace(char *p)
{
int i;
int m=0;
for(i=0;i<20;i++)
{
if(*(p+i)=='t')
{
*(p+i)='e';
m++;
}
if(*(p+i)=='T')
{
*(p+i)='E';
m++;
}
}
return m;
}
作业3
#include<stdio.h>
int main()
{
int a;
char s[7][20]={
"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"
};
char *p[7];
int i;
for(i=0;i<7;i++)
{
p[i]=s[i];
}
while(scanf("%d",&a)&&a<8&&a>0)
{
puts(p[a-1]);
}
}