I use this code but it doesn't work properly.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main() {
char line[120], *word;
int o, row, col, letter, i;
o = scanf("%s", line);
row = 0;
while(o != -1) {
col = 0;
while(isprint(line[col])) {
word = (char *) malloc(sizeof(char)*20);
for(i=0; i<20; i++) *(word + i) = 0;
letter = 0;
while(isalpha(line[col])) {
*(word + letter) = line[col];
col++;
letter++;
}
col++;
printf("%s\n", word);
free(word);
}
row++;
o = scanf("%s", line);
}
return 0;
}
For example, I give as input:
can you take a string?
and I take as output:
can
you
take
a
ke
string
I can't find the mistake, but the fact that the output isn't far from what I want means that the mistake is small. Please help me...:)