[ create a new paste ] login | about

Link: http://codepad.org/VfIegr4T    [ raw code | output | fork ]

slevy1ster - C, pasted on Jan 27:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void convert_to_arr(char ** sv) {

   int i=0,j=0,n=0;
  
   char * nums[3][4];
   char * numstr[(3 * 4)];
   char   tempstr[4];

   for (i=0,n=0; i < 3; i++) {
            for (j=0; j < 4; j++) {
               if (i== 2 && j == 3) break;
               nums[i][j] = sv[n++];
            }
    }

    puts("\nOutputting array of three strings and 3 chars in ea:");    
    for (i=0; i < 3; i++) { 
         strcpy( tempstr, nums[i][0] );
         strcat( tempstr,nums[i][1] );
         strcat( tempstr,nums[i][2] );
         numstr[i] = tempstr;
         puts(numstr[i]);
     }
}

int main()
{
    int count = 0;
     
    char str[] = "1,2,3,\n,4,5,6,\n,7,8,9";
    char * save[80];     
    const char s[2] = ",";
    char *token;
 
    printf("Data to parse:\n \"%s\"\n",str);
  
   /* setup */
   token = strtok(str, s);
   
   /* get tokens */
   while( token != NULL ) 
   {
      
      save[count] = token;
      count++; 
      token = strtok(NULL, s);
      
   }

  
   convert_to_arr(&save);    
   return 0;
}


Output:
1
2
3
4
5
6
7
8
9
Data to parse:
 "1,2,3,
,4,5,6,
,7,8,9"

Outputting array of three strings and 3 chars in ea:
123
456
789


Create a new paste based on this one


Comments: