I'm trying to create a function which converts the following string:
1110100010000000101000011000011110000000000000000000000000111101110000110101100111
to:
1110100010000000 1010 0001 1000 0111 1000 0000 0000 0000 0000 0000 0011 1101 1100 0011 0101 1001 11
(groups of four 1's/0's)
Some function like the following:
convert(char *src_buffer,char *dst_buffer,int offset){
}
where "offset" is 16 in the above case.
Here's the code I've tried sofar:
char *tmp=(char*)malloc(1000*sizeof(char));
strncpy(tmp,buffer,i);
tmp[i+1]=' ';
for(int j=0;j<sizeof(buffer);j++){
strcpy(tmp+sizeof(tmp),buffer+(4*j));
tmp[(5*j)+1]=' ';
}
But it just won't work...
Please help! I'm hoping there's a C guru out there who can help me.
Here's some updated code I've been working on:
char *tmp=(char*)malloc(1000*sizeof(char));
strncpy(tmp,buffer,offset);
tmp[offset+1]=' ';
int k=offset+1;
for(int j=i;j<strlen(buffer);j+=4){
tmp[k]=buffer[j];
tmp[k+1]=buffer[j+1];
tmp[k+2]=buffer[j+2];
tmp[k+3]=buffer[j+3];
tmp[k+5]=' ';
k+=5;
}