My problem statement was to accept a string of numbers and display the different numbers on screen. So i tried to use strtok() to divide the string to different numbers and atoi() to convert these to numbers. But I'm getting runtime error.. I have also attached a sample code.
Input
1 22 123 89 12 as a string
Output
1 22 123 89 12 as numbers
I need to do mathematical operations on these numbers. So I must convert from integer to string.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main ()
{
    int i,j;
    char buffer [256];
    char *token;
    const char s[2]= " ";
    fgets (buffer, 256, stdin);
    token=strtok(buffer,s);
    i = atoi (token);
    printf("%d \n",i);
    while (token!=NULL)
                {token=strtok(buffer,s);
                i = atoi (token);
                printf("%d ",i);
                }
    return 0;
}
 
     
     
     
     
    