Give a string (max 100 characters) > apple
Give a string (max 100 characters) > Apple
Give a string (max 100 characters) > pointer
Give a string (max 100 characters) > Goofy
Give a string (max 100 characters) > user
A string ending with the letters ‘er’ is “pointer”
A string ending with the letters ‘er’ is “user”
检查最后两个字符是不是e和r就行
#include <stdio.h>
#include <string.h>
int main()
{
char a[5][101] = {0};
int i,len;
for (i=0;i<5;i++)
{
printf("Give a string (max 100 characters) > ");
gets(a[i]);
}
for (i=0;i<5;i++)
{
len = strlen(a[i]);
if(a[i][len-2] == 'e' && a[i][len-1] == 'r')
printf("A string ending with the letters ‘er’ is \"%s\"\n",a[i]);
}
return 0;
}