title: C programming, error loop due to scanf?
body: <p>I have question about <code>scanf</code> a string. I am completing a practice exercise on encoding a Vigenere cipher. </p>
  
  <p>It is easy to solve it at other language but in C I have trouble and I don't know why it is.  </p>
  
  <p>This is my code. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  main()
  {
      char mes[1000];
      char key[100];
      int n=strlen(mes);
      int cipher[n],i,j=0;
  
      printf("Enter message \n");
      scanf("%s",mes);
  
      printf("Enter keyword \n");
      scanf("%s",key);
      printf("len message= %d \n",strlen(mes));
  
      for(i=0;i&lt;strlen(mes);++i)
      {
          mes[i]=toupper(mes[i]);
          key[j]=toupper(key[j]);
          if(j==strlen(key))
              j=0;
          cipher[i]=((mes[i]-0x41)+(key[j]-0x41)) % 26;
          printf("%c",cipher[i]+0x41);
          ++j;}
      printf("\n");
  }
  </code></pre>
  
  <p>My code work well if <code>mes</code> array input is less than 16 character, but if <code>mes</code> input larger the program loop infinite. I don't know why. </p>
  
  <p>If I change type of <code>cipher</code> array to char type, it seem work better, but the result still have wrong output like this: </p>
  
  <pre><code>Enter message 
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  Enter keyword 
  eeeeeeeeeeeeeeeeeee
  len of message= 45
  EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE�EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEEEEE
  </code></pre>
  
  <p>So can you explain:</p>
  
  <p>1) Why my code do wrong if <code>cipher</code> array is an <code>int</code> type?</p>
  
  <p>2) If <code>cipher</code> is char, the output better but why It have wrong output?</p>