ใครเก่งโค้ด ภาษา C มาอธิบายทีครับ

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>
struct contact
{
    char ph[20];
    char name[30],add[30],email[30];
} list;
char query[20],name[30];
FILE *fp, *ft;
int i,n,ch,length;
int main()
{
main:
    system("cls");    
    printf("\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t[1] Add new Contact\n\t\t[2] List Contacts\n\t\t[3] Search Contact\n\t\t[4] Edit Contact\n\t\t[5] Delete 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;
           
    case 1:
        system("cls");
        do
         {
          fp=fopen("contact.txt","a");
             fflush(stdin);
             printf("\nName:");
             scanf("%[^\n]",&list.name);
             fflush(stdin);
             printf("Phone:");
             scanf("%s",&list.ph);
             fflush(stdin);
             printf("address:");
             scanf("%[^\n]",&list.add);
             fflush(stdin);
             printf("email address:");
             scanf("%[^\n]",&list.email);
             printf("\n");
             fwrite(&list,sizeof(list),1,fp);       
           fclose(fp);
            printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");
            scanf("%d",&ch);
         }
         while(ch==1);
        break;
        
    case 2:
        system("cls");
        printf("\n==========================SHOW LIST CONTACT=====================================\n");
            fp=fopen("contact.txt","r");
            fflush(stdin);
            while(fread(&list,sizeof(list),1,fp)==1)
            {
                    printf("\nName\t: %s\nPhone\t: %s\nAddress\t: %s\nEmail\t: %s\n",list.name,list.ph,list.add,list.email);                        
            }
            fclose(fp);
            break;
        
    case 3:
        system("cls");
        do
        {
            printf("\n\n\t::CONTACT SEARCH\n\t===========================\n\t::Name of contact to search: ");
            fflush(stdin);
            scanf("%[^\n]",&query);
            length=strlen(query);
            fp=fopen("contact.txt","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<=length; i++)
                {                
                    name=list.name;
                }
                name[length]='\0';
                if(strcmp(name,query)==0)
                {
                    printf("\n..::Name\t: %s\n..:เค้าล้อเล่นhone\t: %s\n..::Address\t: %s\n..::Email\t: %s\n",list.name,list.ph,list.add,list.email);                   
                }
            }
            fclose(fp);
            printf("\n ::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");
            scanf("%d",&ch);
        }
        while(ch==1);
        break;
        
    case 4:
        system("cls");
        fp=fopen("contact.txt","r");
        ft=fopen("new.txt","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(strcmp(name,list.name)!=0)
                fwrite(&list,sizeof(list),1,ft);
        }
        fflush(stdin);
        printf("\n\n::Editing '%s'\n\n",name);
        printf("::Name:");
        scanf("%[^\n]",&list.name);
        fflush(stdin);
        printf(":เค้าล้อเล่นhone:");
        scanf("%s",&list.ph);
        fflush(stdin);
        printf("::address:");
        scanf("%[^\n]",&list.add);
        fflush(stdin);
        printf("::email address:");
        scanf("%[^\n]",&list.email);
        printf("\n");
        fwrite(&list,sizeof(list),1,ft);
        fclose(fp);
        fclose(ft);
        remove("contact.txt");
        rename("new.txt","contact.txt");
        break;
        
    case 5:
        system("cls");
        fflush(stdin);
        printf("\n\n\t:หัวเราะELETE A CONTACT\n\t==========================\n\t::Enter the name of contact to delete:");
        scanf("%[^\n]",&name);
        fp=fopen("contact.txt","r");
        ft=fopen("new.txt","w");
        while(fread(&list,sizeof(list),1,fp)!=0)
            if (strcmp(name,list.name)!=0)
                fwrite(&list,sizeof(list),1,ft);
        fclose(fp);
        fclose(ft);
        remove("contact.txt");
        rename("new.txt","contact.txt");
        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;

}
1.อยากรู้ว่า fwrite เวลาเก็บข้อมูลมันเก็บแบบไหน เพราะเวลาเก็บในไฟล์เปิดไฟล์มามันเป็นข้อมูลแถวยาวๆ ต่อๆ แล้วเวลามันเอาข้อมูลมาใช้ มันรู้ได้ยังไงว่าต้องเอาตรงนี้มาใช้
2.ทำไม case 3  ต้องใช้ name[length] ='\0'; มันมีผลยังไง แล้วทำไมต้องใส่
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่