Currently I'm trying to take a binary string, say 100101010, and split it into groups of three, so 100 101 010. Here's what I've written so far, for some reason it only prints the first group, 100 and then nothing after that.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
int i;
char *line = NULL;
free(line);
scanf("%ms", &line);
printf("%d\n", strlen(line));
for(i=0; i < strlen(line); ++i) {
if ( i % 3 == 0 ){
sprintf(line, "%c%c%c", line[i],line[i+1],line[i+2]);
printf(line);
}
}
}
line = NULL, so it's pointless. Why include pointless code - it makes the real problems harder to spot... BTW - you don't actually free line at the end, so you have a free where you don't need it and are missing one where you do ;-)