title: How to read a sequence of space separated integers until newline character is encountered?
body: <p>I have been trying to write a program that would read a sequence of space separated integers until the newline character is encountered.My approach was to read the input as a string and using <code>atoi()</code> to convert the string to integer.
  This is my approach:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;ctype.h&gt;
  
  int main()
  {
  int a[100],i=0,k=0;
  char s[100];
  
  //Read the first character
  scanf("%c",&amp;s[i]);
  
  //Reads characters until new line character is encountered
  while(s[i]!='\n'){
      i+=1;
      scanf("%c",&amp;s[i]);
  }
  
  //Print the String
  printf("\nstring = %s\n",s);
  
  //Trying to convert the characters in the string to integer
  for(i=0;s[i]!='\0';i++){
      if(isdigit(s[i]))
      {
          a[k] = atoi(s);
          k+=1;
      }
  }
  
  //Printing the integer array
  for(i=0;i&lt;k;i++)
  printf("%d ",a[i]);
  return 0;
  }
  </code></pre>
  
  <p>But when I enter the input <code>1 2 3 4</code> the output is <code>1 1 1 1</code>. All I want is to read the string and convert the characters of the string entered into terms of an Integer array <code>a[0] = 1 a[1] = 2 a[3]= 3 a[4] = 4</code>.I probably think <code>a[k] = atoi(s)</code> makes the reference to the first element in the string but not others.So every iteration is assigning <code>a[k] = 1</code>.How to get the desired result?</p>
  
  <p>Thanks in advance.</p>