编写一个C语言函数,要求输入一个url,输出该url是首页、目录页或者其他url

本文介绍了一个使用C语言编写的简单URL分析函数,能够判断输入的URL是否为主页、目录页或其他类型的URL。通过计数斜杠('/')的数量来区分不同类型的URL,并针对含有'http://'前缀的URL进行特别处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

编写一个C语言函数,要求输入一个url,输出该url是首页、目录页或者其他url

如下形式叫做首页:

militia.info/

www.apcnc.com.cn/

http://www.cyjzs.comwww.greena888.com/

www.800cool.net/

http://hgh-products.my-age.net/

如下形式叫做目录页:

thursdaythree.net/greenhouses–gas-global-green-house-warming/

http://www.mw.net.tw/user/tgk5ar1r/profile/

http://www.szeasy.com/food/yszt/chunjie/

www.fuckingjapanese.com/Reality/

 

 

void AnalyseUrlDo(char urls[][256], int n) {

for(int i = 0; i < n; i++) {

int main_flag = 0;

int else_flag = 0;

bool http = false;

 

if(strncmp("http:", urls[i], 5) == 0) {

http = true;

}

 

for(int j = 0; urls[i][j] != '/0'; j++) {

if(urls[i][j] == '/') {

main_flag++;

} else if(urls[i][j] == '?") {

else_flag++;

}

}

if(http) {

if(main_flag == 3 && else_flag == 0) {

cout << urls[i] << "------> main url" << endl;

} else if(main_flag != 3 && else_flag == 0) {

cout << urls[i] << "------> dir url" << endl;

} else {

cout << urls[i] << "-------> else url" << endl; 

}

} else {

if(main_flag == 1 && else_flag == 0) {

cout << urls[i] << "------> main url" << endl;

} else if(main_flag != 1 && else_flag == 0) {

cout << urls[i] << "-------> dir url" << endl;

} else {

cout << urls[i]  << "------> else url" << endl;

}

}

}

}

 

 

 

 

//test function

void main() {

char datas[11][100] = {"militia.info/",   

"www.apcnc.com.cn/",   

"http://www.cyjzs.comwww.greena888.com/",   

"www.800cool.net/",   

"http://hgh-products.my-age.net/",   

"thursdaythree.net/greenhouses--gas-global-green-house-warming/",   

"http://www.mw.net.tw/user/tgk5ar1r/profile/",   

"http://www.szeasy.com/food/yszt/chunjie/",   

"www.fuckingjapanese.com/Reality/",   

"www.buddhismcity.net/utility/mailit.php?l=/activity/details/3135/",   

"www.buddhismcity.net/utility/mailit.php?l=/activity/details/2449/"  };   

 

 AnalyseUrlDo(datas, 11);   

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值