#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "website.h"
web _url;
int main()
{
char select;//菜单选项
char ensure;//确认
FILE*pf;//文件流
int n = 0; //网址编号
char url[1024];//网址
char name[1024];//网站名称
int count;
char go_url[1024 + 14] = {"start http://"};
//---------------------------------------------
ComeBack_MainMenu://回到主菜单
{
printf(" 网址收藏\n");
printf("**************\n");
printf("* 1:添加网址 *\n");
printf("* 2:访问网址 *\n");
printf("* 3:删除网址 *\n");
printf("**************\n");
printf("版本:1.0\n");
}
//---------------------------------------------
select = getch(); //输入选项
switch (select) //判断跳转
{
case '1':
goto add_url;
case '2':
goto visit_url;
case '3':
goto del_url;
}
//---------------------------------------------
add_url:
{
pf = fopen("UrlData", "a+b"); //打开流
system("cls");
while (fread(&_url, sizeof(web), 1, pf ) != 0)
{
n = _url.on;
}
n++;
printf("请添加网址(首字符输入 # 表示返回主菜单)>");
scanf("%s", url);
if (url[0] == '#')
{
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
printf("请备注(首字符输入 # 表示返回主菜单)>");
scanf("%s", name);
if (name[0] == '#')
{
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
//-----------------------------------------
printf("您确定保存该网址吗?(Y or N)");
ensure = getch();//提示用户确认保存
switch (ensure) //判断跳转
{
case 'Y':
case 'y':
_url = AddUrl(url, name, n);
fwrite(&_url, sizeof(web), 1, pf);
fclose(pf);
system("cls");
break;
case 'N':
case 'n':
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
//-----------------------------------------
goto visit_url;
}
//---------------------------------------------
visit_url:
{
n = -1;
if ((pf = fopen("UrlData", "rb")) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
goto ComeBack_MainMenu;
}
if (fread(&_url, sizeof(web), 1, pf ) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
system("cls");
printf("%d---返回主菜单\n", 0);
do {
ShowUrl(&_url, &count);
} while (fread(&_url, sizeof(web), 1, pf ) != 0);
printf("现在请您输入要访问网址的编号>");
//---------------------------------------------
visit_mistake://重新输入
{
scanf("%d", &n);
}
if (n == 0)
{
system("cls");
goto ComeBack_MainMenu;
}
if (n < 0)
{
while (getchar() != '\n');
printf("您的输入无效!\n请重新输入>");
goto visit_mistake;
}
if (n > count)
{
printf("没有找到该编号!\n请重新输入>");
n = -1;
goto visit_mistake;
}
}
//---------------------------------------------
//访问网站
fseek(pf, ( n - 1)*sizeof(web), SEEK_SET);
fread(&_url, sizeof(web), 1, pf );
strcat(go_url, _url.url);
system(go_url);
system("cls");
fclose(pf);
strcpy(go_url, "start http://");
goto ComeBack_MainMenu;//返回主页
//---------------------------------------------
del_url:
{
web* url_arr;
int i = 0;
n = -1;
if ((pf = fopen("UrlData", "rb")) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
if (fread(&_url, sizeof(web), 1, pf ) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
system("cls");
printf("%d---返回主菜单\n", 0);
do {
i++;
ShowUrl(&_url, &count);
} while (fread(&_url, sizeof(web), 1, pf ) != 0);
url_arr = (web*)malloc(sizeof(web) * i);
printf("现在请您输入要删除网址的编号>");
del_mistake://重新输入
{
scanf("%d", &n);
}
if (n == 0)
{
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
if (n < 0)
{
while (getchar() != '\n');
printf("您的输入无效!\n请重新输入>");
goto del_mistake;
}
if (n > count)
{
printf("没有找到该编号!\n请重新输入>");
n = -1;
goto del_mistake;
}
rewind(pf);
for (i = 0;; i++)
{
if (fread(&_url, sizeof(web), 1, pf ) == 0) {
break;
}
if (i == n - 1)
{
i--;
continue;
}
url_arr[i] = _url;
}
n = i;
fclose(pf);
pf = fopen("UrlData", "wb");
for (i = 0; i < n; i++)
{
fwrite(&url_arr[i], sizeof(web), 1, pf);
}
fclose(pf);
system("cls");
goto visit_url;
}
}
#include<string.h>
#include<stdlib.h>
#include "website.h"
web _url;
int main()
{
char select;//菜单选项
char ensure;//确认
FILE*pf;//文件流
int n = 0; //网址编号
char url[1024];//网址
char name[1024];//网站名称
int count;
char go_url[1024 + 14] = {"start http://"};
//---------------------------------------------
ComeBack_MainMenu://回到主菜单
{
printf(" 网址收藏\n");
printf("**************\n");
printf("* 1:添加网址 *\n");
printf("* 2:访问网址 *\n");
printf("* 3:删除网址 *\n");
printf("**************\n");
printf("版本:1.0\n");
}
//---------------------------------------------
select = getch(); //输入选项
switch (select) //判断跳转
{
case '1':
goto add_url;
case '2':
goto visit_url;
case '3':
goto del_url;
}
//---------------------------------------------
add_url:
{
pf = fopen("UrlData", "a+b"); //打开流
system("cls");
while (fread(&_url, sizeof(web), 1, pf ) != 0)
{
n = _url.on;
}
n++;
printf("请添加网址(首字符输入 # 表示返回主菜单)>");
scanf("%s", url);
if (url[0] == '#')
{
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
printf("请备注(首字符输入 # 表示返回主菜单)>");
scanf("%s", name);
if (name[0] == '#')
{
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
//-----------------------------------------
printf("您确定保存该网址吗?(Y or N)");
ensure = getch();//提示用户确认保存
switch (ensure) //判断跳转
{
case 'Y':
case 'y':
_url = AddUrl(url, name, n);
fwrite(&_url, sizeof(web), 1, pf);
fclose(pf);
system("cls");
break;
case 'N':
case 'n':
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
//-----------------------------------------
goto visit_url;
}
//---------------------------------------------
visit_url:
{
n = -1;
if ((pf = fopen("UrlData", "rb")) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
goto ComeBack_MainMenu;
}
if (fread(&_url, sizeof(web), 1, pf ) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
system("cls");
printf("%d---返回主菜单\n", 0);
do {
ShowUrl(&_url, &count);
} while (fread(&_url, sizeof(web), 1, pf ) != 0);
printf("现在请您输入要访问网址的编号>");
//---------------------------------------------
visit_mistake://重新输入
{
scanf("%d", &n);
}
if (n == 0)
{
system("cls");
goto ComeBack_MainMenu;
}
if (n < 0)
{
while (getchar() != '\n');
printf("您的输入无效!\n请重新输入>");
goto visit_mistake;
}
if (n > count)
{
printf("没有找到该编号!\n请重新输入>");
n = -1;
goto visit_mistake;
}
}
//---------------------------------------------
//访问网站
fseek(pf, ( n - 1)*sizeof(web), SEEK_SET);
fread(&_url, sizeof(web), 1, pf );
strcat(go_url, _url.url);
system(go_url);
system("cls");
fclose(pf);
strcpy(go_url, "start http://");
goto ComeBack_MainMenu;//返回主页
//---------------------------------------------
del_url:
{
web* url_arr;
int i = 0;
n = -1;
if ((pf = fopen("UrlData", "rb")) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
if (fread(&_url, sizeof(web), 1, pf ) == 0)
{
system("cls");
printf("目前您还没有添加过网址\n按任意键返回主菜单......");
getch();
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
system("cls");
printf("%d---返回主菜单\n", 0);
do {
i++;
ShowUrl(&_url, &count);
} while (fread(&_url, sizeof(web), 1, pf ) != 0);
url_arr = (web*)malloc(sizeof(web) * i);
printf("现在请您输入要删除网址的编号>");
del_mistake://重新输入
{
scanf("%d", &n);
}
if (n == 0)
{
system("cls");
fclose(pf);
goto ComeBack_MainMenu;
}
if (n < 0)
{
while (getchar() != '\n');
printf("您的输入无效!\n请重新输入>");
goto del_mistake;
}
if (n > count)
{
printf("没有找到该编号!\n请重新输入>");
n = -1;
goto del_mistake;
}
rewind(pf);
for (i = 0;; i++)
{
if (fread(&_url, sizeof(web), 1, pf ) == 0) {
break;
}
if (i == n - 1)
{
i--;
continue;
}
url_arr[i] = _url;
}
n = i;
fclose(pf);
pf = fopen("UrlData", "wb");
for (i = 0; i < n; i++)
{
fwrite(&url_arr[i], sizeof(web), 1, pf);
}
fclose(pf);
system("cls");
goto visit_url;
}
}