我使用此代码,但它不能正常工作。
#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;
}
例如,我给作为输入:
can you take a string?
我把它作为输出:
can
you
take
a
ke
string
我找不到错误,但是输出与我想要的不远的事实意味着错误很小。请帮我...:)