#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void split( char * ch, char ** part1, char ** part2, int * num) {
char * lc1,* lc2;
int i= 0 , j= 0 ;
printf ( "value of length is %d\n " , length
) ;
printf ( "this function recieved %s for splitting into pieces\n " , ch
) ;
lc1
= ( char * ) malloc ( length
* sizeof ( char ) ) ; lc2
= ( char * ) malloc ( length
* sizeof ( char ) ) ;
while ( ch[ i] != ' ' ) {
lc1[ i] = ch[ i] ;
printf ( "\n in loop with lc1[i] = %c and ch[i] = %c" , lc1
[ i
] , ch
[ i
] ) ; i++;
}
lc1[ i] = '\0 ' ;
i++;
while ( ch[ i] != ' ' ) {
lc2[ j] = ch[ i] ;
printf ( "\n in loop with lc2[j] = %c and ch[i] = %c" , lc2
[ j
] , ch
[ i
] ) ; j++;
i++;
}
lc2[ j] = '\0 ' ;
i++;
* part1= lc1;
* part2= lc2;
printf ( "\n split results are:\n " ) ; printf ( "part1=%s and part2=%s and num=%d and lc1=%s lc2=%s //this is surprising me\n " ,* part1
,* part2
,* num
, lc1
, lc2
) ;
}
int main( )
{
int N, i, j, n,* numArray, count= 0 ;
char ** arr,* part1,* part2,* token;
numArray
= malloc ( N
* sizeof * numArray
) ; for ( i= 0 ; i< N; i++ ) {
arr
[ i
] = ( char * ) malloc ( 50 * sizeof ( char ) ) ; }
for ( i= 0 ; i< N; i++ ) {
printf ( "plz enter %d th :" , i
) ; }
for ( i= 0 ; i< N; i++ ) {
}
for ( i= 0 ; i< N; i++ ) {
/*token=strtok(arr[i]," ");
part1=token;
token=strtok(NULL," ");
part2=token;
token=strtok(NULL," ");
n=atoi(token);*/
split( arr[ i] ,& part1,& part2,& n) ;
//some logic to use part1 and part2 of the sentence
}
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKdm9pZCBzcGxpdChjaGFyICpjaCxjaGFyICoqcGFydDEsY2hhciAqKnBhcnQyLGludC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9CgppbnQgbWFpbigpCnsKICAgIGludCBOLGksaixuLCpudW1BcnJheSxjb3VudD0wOwogICAgY2hhciAqKmFyciwqcGFydDEsKnBhcnQyLCp0b2tlbjsKICAgIHNjYW5mKCIlZCIsJk4pOwogICAgYXJyPW1hbGxvYyhOKnNpemVvZiAqYXJyKTsKICAgIG51bUFycmF5PW1hbGxvYyhOKnNpemVvZiAqbnVtQXJyYXkpOwogICAgZm9yKGk9MDtpPE47aSsrKXsKICAgICAgICBhcnJbaV09KGNoYXIgKiltYWxsb2MoNTAqc2l6ZW9mKGNoYXIpKTsKICAgIH0KCiAgICBmb3IoaT0wO2k8TjtpKyspewogICAgICAgIHByaW50ZigicGx6IGVudGVyICVkIHRoIDoiLGkpOwogICAgICAgIHNjYW5mKCIgIik7CiAgICAgICAgZ2V0cygmYXJyW2ldWzBdKTsKICAgIH0KCiAgICBmb3IoaT0wO2k8TjtpKyspewogICAgICAgIHByaW50ZigiJXNcbiIsYXJyW2ldKTsKICAgIH0KCiAgICBmb3IoaT0wO2k8TjtpKyspewogICAgICAgIC8qdG9rZW49c3RydG9rKGFycltpXSwiICIpOwogICAgICAgICAgcGFydDE9dG9rZW47CiAgICAgICAgICB0b2tlbj1zdHJ0b2soTlVMTCwiICIpOwogICAgICAgICAgcGFydDI9dG9rZW47CiAgICAgICAgICB0b2tlbj1zdHJ0b2soTlVMTCwiICIpOwogICAgICAgICAgbj1hdG9pKHRva2VuKTsqLwogICAgICAgIHNwbGl0KGFycltpXSwmcGFydDEsJnBhcnQyLCZuKTsKICAgICAgICAvL3NvbWUgbG9naWMgdG8gdXNlIHBhcnQxIGFuZCBwYXJ0MiBvZiB0aGUgc2VudGVuY2UKICAgIH0KICAgIHJldHVybiAwOwoKfQo=