Wednesday, 12 August 2015

C program to read array of elements separated by comma and print array of elements



Input   : 2, 6, 7, 8, 1, 0
Output: 2 6 7 8 1 0

Program:

#include< stdio.h >
#include< conio.h >
void main( )
{
          int i = 0;
          char a[ ] = "2, 6, 7, 8, 1, 0";
          char *p, *b[ 10 ];
          p = strtok(a, ",");
          while( p != NULL )
          {
                 b[ i++ ] = p;
                 p = strtok( NULL, ",");
          }
          for( i = 0; i < 6; i++ )
          {
                 printf("%s", b[ i ]);
          }
}

Output:

2 6 7 8 1 0



0 comments:

Post a Comment