Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
你能帮我了解一下fopen(“contact.dll”和“r”)吗;_C_Dll_Directory_Phone Number - Fatal编程技术网

你能帮我了解一下fopen(“contact.dll”和“r”)吗;

你能帮我了解一下fopen(“contact.dll”和“r”)吗;,c,dll,directory,phone-number,C,Dll,Directory,Phone Number,我正在尝试使用数据结构在C中实现电话簿。 我找到了一些源代码,我正在努力理解这些代码,但有一个我从未见过的大问题。这是dll。我在谷歌上搜索了dll,但没有相关内容。我知道dll的含义和用途,但为什么我们要使用fopen contact.dll #include<stdio.h> #include<conio.h> #include<string.h> #include<process.h> #include<stdlib.h> #in

我正在尝试使用数据结构在C中实现电话簿。 我找到了一些源代码,我正在努力理解这些代码,但有一个我从未见过的大问题。这是dll。我在谷歌上搜索了dll,但没有相关内容。我知道dll的含义和用途,但为什么我们要使用
fopen contact.dll

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
#include<dos.h>
struct contact
{
    long phone;
    char name[20],add[20],email[30];
} list;
char query[20],name[20];
FILE *fp, *ft;
int i,n,ch,l,found;
int main()
{
main:
    system("cls");    /* ************Main menu ***********************  */
    printf("\n\t **** Welcome to Contact Management System ****");  
    printf("\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t[1] Add a new Contact\n\t\t[2] List all Contacts\n\t\t[3] Search for contact\n\t\t[4] Edit a Contact\n\t\t[5] Delete a Contact\n\t\t[0] Exit\n\t\t=====================\n\t\t");
    printf("Enter the choice:");
    scanf("%d",&ch);
    switch(ch)
    {
    case 0:
        printf("\n\n\t\tAre you sure you want to exit?");
        break;
        /* *********************Add new contacts************  */
    case 1:
        system("cls");
        fp=fopen("contact.dll","a");
        for (;;)
        {
            fflush(stdin);
            printf("To exit enter blank space in the name input\nName (Use identical):");
            scanf("%[^\n]",&list.name);
            if(stricmp(list.name,"")==0 || stricmp(list.name," ")==0)
                break;
            fflush(stdin);
            printf("phone:");
            scanf("%ld",&list.phone);
            fflush(stdin);
            printf("address:");
            scanf("%[^\n]",&list.add);
            fflush(stdin);
            printf("email address:");
            gets(list.email);
            printf("\n");
            fwrite(&list,sizeof(list),1,fp);
        }
        fclose(fp);
        break;
        /* *********************list of contacts*************************  */
    case 2:
        system("cls");
        printf("\n\t\t================================\n\t\t\tLIST OF CONTACTS\n\t\t================================\n\nName\t\tphone No\t    Address\t\tE-mail ad.\n=================================================================\n\n");
        for(i=97; i<=122; i=i+1)  
        {
            fp=fopen("contact.dll","r");
            fflush(stdin);
            found=0;
            while(fread(&list,sizeof(list),1,fp)==1)
            {
                if(list.name[0]==i || list.name[0]==i-32)
                {
                    printf("\nName\t: %s\nphone\t: %ld\nAddress\t: %s\nEmail\t: %s\n",list.name,
                           list.phone,list.add,list.email);
                    found++;
                }
            }
            if(found!=0)
            {
              printf("=========================================================== [%c]-(%d)\n\n",i-32,found);
                getch();
            }
            fclose(fp);
        }
        break;
        /* *******************search contacts**********************  */
    case 3:
        system("cls");
        do
        {
            found=0;
            printf("\n\n\t..::CONTACT SEARCH\n\t===========================\n\t..::Name of contact to search: ");
            fflush(stdin);
            scanf("%[^\n]",&query);
            l=strlen(query);
            fp=fopen("contact.dll","r");
            system("cls");
            printf("\n\n..::Search result for '%s' \n===================================================\n",query);
            while(fread(&list,sizeof(list),1,fp)==1)
            {
                for(i=0; i<=l; i++)
                    name[i]=list.name[i];
                name[l]='\0';
                if(stricmp(name,query)==0)
                {
                    printf("\n..::Name\t: %s\n..::phone\t: %ld\n..::Address\t: %s\n..::Email\t: %s\n",list.name,list.phone,list.add,list.email);
                    found++;
                    if (found%4==0)
                    {
                        printf("..::Press any key to continue...");
                        getch();
                    }
                }
            }
            if(found==0)
                printf("\n..::No match found!");
            else
                printf("\n..::%d match(s) found!",found);
            fclose(fp);
            printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");
            scanf("%d",&ch);
        }
        while(ch==1);
        break;
        /* *********************edit contacts************************/
    case 4:
        system("cls");
        fp=fopen("contact.dll","r");
        ft=fopen("temp.dat","w");
        fflush(stdin);
        printf("..::Edit contact\n===============================\n\n\t..::Enter the name of contact to edit:");
        scanf("%[^\n]",name);
        while(fread(&list,sizeof(list),1,fp)==1)
        {
            if(stricmp(name,list.name)!=0)
                fwrite(&list,sizeof(list),1,ft);

        }
        fflush(stdin);
        printf("\n\n..::Editing '%s'\n\n",name);
        printf("..::Name(Use identical):");
        scanf("%[^\n]",&list.name);
        fflush(stdin);
        printf("..::phone:");
        scanf("%ld",&list.phone);
        fflush(stdin);
        printf("..::address:");
        scanf("%[^\n]",&list.add);
        fflush(stdin);
        printf("..::email address:");
        gets(list.email);
        printf("\n");
        fwrite(&list,sizeof(list),1,ft);
        fclose(fp);
        fclose(ft);
        remove("contact.dll");
        rename("temp.dat","contact.dll");
        break;
        /* ********************delete contacts**********************/
    case 5:
        system("cls");
        fflush(stdin);
        printf("\n\n\t..::DELETE A CONTACT\n\t===============================\n\t..::Enter the name of contact to delete:");
        scanf("%[^\n]",&name);
        fp=fopen("contact.dll","r");
        ft=fopen("temp.dat","w");
        while(fread(&list,sizeof(list),1,fp)!=0)
            if (stricmp(name,list.name)!=0)
                fwrite(&list,sizeof(list),1,ft);
        fclose(fp);
        fclose(ft);
        remove("contact.dll");
        rename("temp.dat","contact.dll");
        break;
    default:
        printf("Invalid choice");
        break;
    }
    printf("\n\n\n..::Enter the Choice:\n\n\t[1] Main Menu\t\t[0] Exit\n");
    scanf("%d",&ch);
    switch (ch)
    {
    case 1:
        goto main;
    case 0:
        break;
    default:
        printf("Invalid choice");
        break;
    }
    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
结构接触
{
长电话;
字符名称[20],添加[20],电子邮件[30];
}名单;
字符查询[20],名称[20];
文件*fp,*ft;
int i,n,ch,l,found;
int main()
{
主要内容:
系统(“cls”);/*************主菜单***************************/
printf(“\n\t****欢迎使用联系人管理系统****”;
printf(“\n\n\n\t\t\t主菜单\n\t\t=1]添加新联系人\n\t\t[2]列出所有联系人\n\t\t[3]搜索联系人\n\t\t[4]编辑联系人\n\t\t[5]删除联系人\n\t\t[0]退出\n\t\t=========;
printf(“输入选项:”);
scanf(“%d”和“ch”);
开关(ch)
{
案例0:
printf(“\n\n\t\t您确定要退出吗?”);
打破
/***********************添加新联系人***************/
案例1:
系统(“cls”);
fp=fopen(“contact.dll”、“a”);
对于(;;)
{
fflush(stdin);
printf(“要退出,请在名称输入中输入空格\n名称(使用相同):”;
scanf(“%[^\n]”,&list.name);
if(stricmp(list.name,”)==0 | | stricmp(list.name,”)==0)
打破
fflush(stdin);
printf(“电话:”);
scanf(“%ld”和list.phone);
fflush(stdin);
printf(“地址:”);
scanf(“%[^\n]”,&list.add);
fflush(stdin);
printf(“电子邮件地址:”);
获取(list.email);
printf(“\n”);
fwrite(&list,sizeof(list),1,fp);
}
fclose(fp);
打破
/**************************联系人列表*******************************************/
案例2:
系统(“cls”);
printf(“\n\t\t======================================================\n\t\t\t联系人列表\n\t\t==================================================================\n\n姓名\t\t电话没有\t地址\t\t邮件广告。\n======================================================================================================================================================================================================================================================================================================================================================================================================================================================;

对于(i=97;i,从文件的使用方式判断,contact.dll不是实际的Windows dll,而是此应用程序用于存储电话簿条目的数据文件


各种情况都会从文件中添加、删除、更新和检索
列表
条目。给文件起的名称有误导性。

旁白:在
中,对于(i=97;iTL;DR,但是:1)
fflush(stdin)
是未定义的行为,2)避免
goto
在不增加代码可读性的地方(如在代码中).3)使用函数。4)始终检查可能遇到错误的函数的结果。5)
while(ch==1)
?谢谢大家:)对我很有帮助哦,我明白了…你的意思是它与contact.txt或contact.dat类似吗?然后我们可以使用dll作为存储数据的文件吗?不是库文件吗?我听说很多程序都可以共享that@aloefreshman我的意思是调用文件“contact.dll”文件名不是一个好的选择,因为它不是一个动态链接库。它应该被称为“contact.dat”或“phonebook.dat”或类似的名称。@aloefreshman很高兴我能提供帮助。如果您觉得有用,请随时联系。