为什么第二个scanf不执行呢?

时间:2022-03-31 11:24:19
 #include <stdio.h>                                                                                                          |   " Press <F1> to display hel
  2 #define MAX 1000                                                                                                            |   
  3 int isfull(int n);//judge if the list is full or not                                                                        |-  orderlist.c (/root/*明)
  4 void insert(int *p,int len,int i,int elem);//*p represent the first element'id of list,i represent what location do you want||-   macro
     to insert? elem represent what elementdo you want to insert?                                                               |||     MAX
  5 void delete(int *pi,int len,int i);//*p represent the first element'id of list,i represent what location do you want to dele||  
    te?                                                                                                                         ||-   function
  6 int lookelem(int *p,int n,int elem);//what element do you want to look for in the list?;n represent the length of the list. |||     main
  7 main(){                                                                                                                     |||     isfull
  8   int i,j,k;                                                                                                                |||     insert
  9   int loca,elem;                                                                                                            |||     delete
 10   int c;                                                                                                                    |||     lookelem
 11   int s[MAX];                                                                                                               |   
 12   printf("please input  list:");                                                                                            |   ~                          
 13      for(i = 0;i < MAX;i++){                                                                                                |   ~                          
 14           scanf("%d",&s[i]);                                                                                                |   ~                          
 15           if (s[i] == '\n')                                                                                                 |   ~                          
 16             break;                                                                                                          |   ~                          
 17      }                                                                                                                      |   ~                          
 18         printf("please choose: ");                                                                                          |   ~                          
 19   printf("0 represent you want to insert element.\n");                                                                      |   ~                          
 20   printf("1 represent you want to delete element.\n");                                                                      |   ~                          
 21   printf("2 represent you want to look element.\n");                                                                        |   ~                          
 22          scanf("%d",&c);                                                                                                    |   ~                          
 23      //  if((c =getchar()) == '0' ||'1'||'2'||'-1' ){                                                                       |   ~                          
 24            switch(c){                                                                                                       |   ~                          
 25                printf("please choose:");                                                                                    |   ~                          
 26            case '0':                                                                                                        |   ~                          
 27               printf("please input the location and element:");                                                             |   ~                          
 28               scanf("%d,%d",&loca,&elem);                                                                                   |   ~                          
 29               insert(s,i,loca,elem);                                                                                        |   ~                          
 30            case'1':                                                                                                         |   ~                          
 31               printf("please input the location and element:");                                                             |   ~                          
 32               scanf("%d",&loca);                                                                                            |   ~                          
 33               delete(s,i,loca);                                                                                             |   ~                          
 34            case'2':                                                                                                         |   ~                          
 35               printf("please input element:");                                                                              |   ~                          
 36               scanf("%d",&elem);                                                                                            |   ~                          
 37                k = lookelem(s,i,elem);                                                                                      |   ~                          
 38                 if(j == 0 )                                                                                                 |   ~                          
 39                    printf("the list have no element you want look\n");                                                      |   ~                          
 40                 else                                                                                                        |   ~                          
 41                    printf("the list is %d",j);                                                                              |   ~                          
 42            default:                                                                                                         |   ~                          
 43               return -1;                                                                                                    |   ~                          
 44          }                                                                                                                  |   ~                          
 45       // }                                                                                                                  |   ~                          
 46      // else                                                                                                                |   ~                          

 47        // printf("you input error num.\n");

            printf("the last list is:\n");                                                                                          ||  
 49   for(k = 0;k < MAX;k++){                                                                                                   ||-   function
 50     printf("%d",s[k]);                                                                                                      |||     main
 51     if(s[k] == '\0')                                                                                                        |||     isfull
 52        break;                                                                                                               |||     insert
 53   }                                                                                                                         |||     delete
 54 }                                                                                                                           |||     lookelem
 55                                                                                                                             |   
 56 int isfull(int n){                                                                                                          |   ~                          
 57    if(n > MAX)                                                                                                              |   ~                          
 58      printf("the list is full");                                                                                            |   ~                          
 59    else                                                                                                                     |   ~                          
 60      return 0;                                                                                                              |   ~                          
 61 }                                                                                                                           |   ~                          
 62                                                                                                                             |   ~                          
 63 void insert(int *p,int len,int i,int elem){                                                                                 |   ~                          
 64     int j,k;                                                                                                                |   ~                          
 65       for(k = len;k > i;k--)                                                                                                |   ~                          
 66         *(p+k) = *(p+k);                                                                                                    |   ~                          
 67      *(p+k) = elem;                                                                                                         |   ~                          
 68      isfull(len + 1);                                                                                                       |   ~                          
 69      printf("the list is:\n");                                                                                              |   ~                          
 70      for(j = 0;j < len+2;j++)                                                                                               |   ~                          
 71        printf("%d",*(p+j));                                                                                                 |   ~                          
 72 }                                                                                                                           |   ~                          
 73                                                                                                                             |   ~                          
 74 void delete(int *pi,int len,int i){                                                                                         |   ~                          
 75 int j,k;                                                                                                                    |   ~                          
 76   for(j = len;j < i;j--)                                                                                                    |   ~                          
 77     *(pi+j) = *(pi+j-1);                                                                                                    |   ~                          
 78   printf("now the list is:\n");                                                                                             |   ~                          
 79    for(k = 0;k < len;k++)                                                                                                   |   ~                          
 80     printf("%d",*(pi+k));                                                                                                   |   ~                          
 81 }                                                                                                                           |   ~                          
 82                                                                                                                             |   ~                          
 83 int lookelem(int *p,int n,int elem){                                                                                        |   ~                          
 84   int k;                                                                                                                    |   ~                          
 85   for(k = 0;k < n+1;k++){                                                                                                   |   ~                          
 86     if(elem = *(p+k))                                                                                                       |   ~                          
 87       return *p;                                                                                                            |   ~                          
 88     else                                                                                                                    |   ~                          
 89       return 0;                                                                                                             |   ~                          
 90   }                                                                                                                         |   ~                          
 91 }                                                                                                                           |   ~                          
orderlist.c