网址分类问题,根据题目要求分类就行了。。。
#include<stdio.h>
#include<string.h>
#define N 100
int main()
{
int n,l,i,j,k,c,t,f1,f2,P2,P1;
char s[N],pro[N],por[N],hos[N],pat[N];
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++){
scanf("%s",s);
memset(pro,0,sizeof(pro));
memset(hos,0,sizeof(hos));
memset(por,0,sizeof(por));
memset(pat,0,sizeof(pat));
printf("URL #%d\n",i);
l=strlen(s);
f1=0; f2=0; P1=0; P2=0;
for(j=0;j<l;j++){
if(s[j]==':'&&s[j+1]=='/'&&s[j+2]=='/'){
for(k=0;k<j;k++) pro[k]=s[k];
pro[k]='\0'; k=j+3;
break;
}
}
for(j=k;j<l;j++){
if(s[j]==':'){ f1=1; P1=j; }
if(s[j]=='/'){ f2=1; P2=j; break; }
}
if(f1==1&&f2==0){
for(j=k;j<P1;j++) hos[j-k]=s[j];
hos[P1-k]='\0';
for(j=P1+1;j<l;j++) por[j-P1-1]=s[j];
por[l-P1-1]='\0';
strcpy(pat,"<default>");
}
else if(f1==1&&f2==1){
for(j=k;j<P1;j++) hos[j-k]=s[j];
hos[P1-k]='\0';
for(j=P1+1;j<P2;j++) por[j-P1-1]=s[j];
por[P2-P1-1]='\0';
for(j=P2+1;j<l;j++) pat[j-P2-1]=s[j];
pat[l-P2-1]='\0';
}
else if(f1==0&&f2==0){
for(j=k;j<l;j++) hos[j-k]=s[j];
hos[l-k]='\0';
strcpy(por,"<default>");
strcpy(pat,"<default>");
}
else{
for(j=k;j<P2;j++) hos[j-k]=s[j];
hos[P2-k]='\0';
for(j=P2+1;j<l;j++) pat[j-P2-1]=s[j];
pat[l-P2-1]='\0';
strcpy(por,"<default>");
}
printf("Protocol = %s\n",pro);
printf("Host = %s\n",hos);
printf("Port = %s\n",por);
printf("Path = %s\n",pat);
printf("\n");
}
}
return 0;
}