נשלח בתאריך: 30 October 2008 בשעה 12:40 | | IP רשוּם
|
|
|
|
הנה בצורה יותר מובנת :
#include <stdio.h> #include <stdlib.h> #include <string.h>
char *sentence(char ** words){
char *newstring, *save; int length, lines;
for(lines = length=0; ; lines++){ length = length + strlen(*(words + lines) ) + 1; if(*(*(words + lines) + strlen(*(words + lines)) - 1) == '.') break; }
newstring = (char *)malloc(length * sizeof(char)); newstring[0] = '\0'; for( save = *(words) ; *(words) <= save + lines ; *(words) ++){ strcat(newstring, *(words)); if(*(words) < save + lines) strcat(newstring, " "); else newstring[length - 1] = '\0'; } return newstring; }
void maim() { char *words[]={{"a"},{"picture"},{"is"},{"worth"},{"a"},{"thousand"},{"words"}}; char *word=sentence(words); puts(word); }
|