fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define DATA_SIZE 6
  5.  
  6. struct ticket_reserve {
  7. char name[30];
  8. char depart_code[4]; //depart=出発 3桁のコード
  9. char arrive_code[4]; //arrive=到着
  10. // char depart_time[8]; //出発時刻 例:12220302 = 12月22日3月2日
  11. // char arrive_time[8]; //到着時刻
  12. char depart_time[9]; //出発時刻 例:12220302 = 12月22日3月2日
  13. char arrive_time[9]; //到着時刻
  14. };
  15.  
  16.  
  17. struct ticket_reserve ticket_date[DATA_SIZE] = {
  18. {"美しい海便", "ac2", "gt6", "12220302", "12230304"},
  19. {"風が気持ちいい便", "ac2", "df7", "12220502", "12220503"},
  20. {"夏を感じる便", "de4", "iu8", "04021211", "04021213"},
  21. {"寒いけど心が引き締まる便","3e2", "te2", "01110825", "01110827"},
  22. {"真夏の夜を感じる便", "ff4", "ff9", "08250101", "08250106"},
  23. {"ネタがねぇ便", "gt6", "gr2", "06311112", "06311114"}
  24. };
  25.  
  26. char search_depart_code1[4] = "ac2";
  27. char search_depart_code2[4] = "de4";
  28.  
  29. int main(void)
  30. {
  31. int i;
  32. for ( i=0; i<=DATA_SIZE - 1; i++) {
  33. // if( ticket_date[i].depart_code == search_depart_code1)
  34. if(strncmp(ticket_date[i].depart_code, search_depart_code1, sizeof(search_depart_code1)) == 0)
  35. printf("出発便[%s]を見つけました!:出発コード%s\n", ticket_date[i].name, ticket_date[i].depart_code);
  36.  
  37. // if( ticket_date[i].depart_code == search_depart_code2)
  38. if(strncmp(ticket_date[i].depart_code, search_depart_code2, sizeof(search_depart_code2)) == 0)
  39. printf("出発便[%s]を見つけました!:出発コード%s\n", ticket_date[i].name, ticket_date[i].depart_code);
  40. }
  41.  
  42. // getchar();
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
出発便[美しい海便]を見つけました!:出発コードac2
出発便[風が気持ちいい便]を見つけました!:出発コードac2
出発便[夏を感じる便]を見つけました!:出発コードde4