2015-11-01 224 views
-2
#include <stdio.h> 
#include <cs50.h> 
#include <stdbool.h> 


typedef struct shop { 

     string custName; 

     string custAdd; 

     string custNum; 

     string custClothPrice; 



struct shop* next; 

} 

shop; 



int main (void) 



{ 
struct shop* head; 



    head = NULL; 

struct shop* pointer=NULL; 


printf("**********WELCOME TO AZIZIYAH CREATIONS**********\n\n"); 

char cont = 'y'; 


printf("Please enter customer details\n"); 

printf("Please Enter NAME : "); 



    head->custName = GetString(); 

printf("Please Enter Address: "); 

    head->custAdd = GetString(); 

printf("Please Enter Cell No: "); 

    head->custNum = GetString(); 
printf("Please Enter Price : "); 

    head->custClothPrice = GetString(); 

return 0; 

printf("Would you liked to add more customer(s)?: Y/N:"); 


    cont = GetChar(); 

    head->next = pointer; 

if (cont == 'Y' || cont == 'y') 



{ 

    pointer = malloc(sizeof(shop)); 

    pointer->next = NULL; 

    } 
while (cont == 'y' || cont == 'Y') 

{ 

printf("Please enter customer details\n"); 

printf("Please Enter NAME : "); 

    pointer->custName = GetString(); 

printf("Please Enter Address: "); 

    pointer->custAdd = GetString(); 

printf("Please Enter Cell No: "); 

    pointer->custNum = GetString(); 

printf("Please Enter Price : "); 

    pointer->custClothPrice = GetString(); 

printf("Would you liked to add more customer(s)?: Y/N:"); 

    cont = GetChar(); 
if (cont == 'Y' || cont == 'y') 

{ 

    pointer->next = malloc(sizeof(shop)); 
    pointer = pointer ->next; 

     } 



    } 

printf("\n\nDETAILS OF CUSTOMER ARE AS FOLLOWS:-\n"); 

struct shop* traverse; 

    traverse = head; 

    if (traverse->next == NULL) 

printf("WAS FOUND NULL\n"); 



while (traverse->next != NULL) 

{ 

printf("%s\n", traverse->custName); 

printf("%s\n", traverse->custAdd); 

printf("%s\n", traverse->custNum); 

printf("%s\n", traverse->custClothPrice); 

    traverse = traverse->next; 
    } 

    printf("**********THANK YOU FOR VISITING**********\n"); 

} 

必須首先輸入 輸出後使其產生分段故障(核心轉儲)的誤差的應用 ********** WELCOME TO阿齊濟耶CREATIONS **********核心轉儲?

請輸入客戶信息 請輸入姓名:ASD 分割故障(核心轉儲)

好心幫助,請

+1

請務必寫下您的問題,「請好心幫忙」不是問題。我們應該怎樣幫助你?你想讓我們做什麼? – fuz

+0

請格式化您的代碼。 –

回答

1

分配給head->custName使你的崩潰:你需要分配內存˚F或head,然後才能將其寫入指向的位置。如果你不這樣做,你的程序崩潰。你可以用malloc()像這樣head分配內存:

head = malloc(sizeof *head); 
if (head == NULL) { 
    /* error handling code here */ 
} 

記住插入相應的錯誤處理代碼。

+0

好了,但請您詳細說明一下嗎? – SayYid

+1

@SayYid您希望我詳細說明一下嗎? – fuz

+0

做了兄弟謝謝。 – SayYid