c言語で文字列の比較を実装しようとしています.
内容は都道府県名を入力し,あらかじめ用意してあるデータ配列(一部の都道府県)と比較するプログラムです.
このとき福島県の比較だけstrcmpの動作だけ正常に比較されないのですがなぜでしょうか.
c言語
1#include<stdio.h> 2#include<stdlib.h> 3#include<string.h> 4#include<limits.h> 5#define MAX_SIZE 13 6char *graph_data[] = { 7 "Tokyo", 8 "Saitama", 9 "Gunma", 10 "Chiba", 11 "Ibaraki", 12 "Tochigi", 13 "Fukushima", 14 "Niigata", 15 "Yamagata", 16 "Miyagi", 17 "Akita", 18 "Iwate", 19 "Aomori" 20}; 21int main(){ 22 int flag; 23 int s_start; 24 int s_destination; 25 char start[10],destination[10]; 26 27 do{ 28 fgets(start,sizeof(start),stdin); 29 start[strlen(start)-1]='¥0'; //改行コードを消す 30 for(int i=0;i<MAX_SIZE;i++){ 31 if(strcmp(start,graph_data[i])==0){ 32 s_start=i; 33 flag=1; 34 break; 35 } 36 } 37 if(flag==-1)printf("The city name does not exist. Please enter the departure city again. :"); 38 }while(flag!=1); 39 printf("start %s¥n",graph_data[s_start]); 40 41} 42
for 文の直前で start を表示してみれば分かると思います。