Question:

How can i split this string and store it into array?? in c

by  |  earlier

0 LIKES UnLike

this is a string:

this , is , me

i want this is string array like this using c

array[0] = "this"

array[1] = "is"

array[2] = "me"

plz help me im stuck in thjis simple thing.........uaaaaaannn any plz help me.

 Tags:

   Report

2 ANSWERS


  1. If you know the exact format of the input string (i.e., you know the number of words and the exact separators), then you could use sscanf().

    /* --------------------- */

    #include <stdio.h>

    char str[] = "this , is , me";

    char* array[3]; /* array of strings */

    sscanf(str, "%s , %s , %s", array[0], array[1], array[2]);

    /* --------------------- */


  2. main()

    {

    char str[]="this  , is ,me";

    char arr[3];

    int i=0,j=0;

    while(j!=strlen(str))

    {

    if(str[j]!=',')

    arr[i]=str[j];

    else

    i++;

    }

    print all the three arrays

    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions