:
This message was edited by AsmGuru62 at 2006-4-17 4:31:53
:
You need to build the list of words in that text. Then calculate the number of spaces between words:
:
: N spaces = (WIDTH - SUM OF ALL WORDS LENGTH) / (WORD COUNT - 1);
:
: Watch out for a single word text - that will give you divide by zero error, so you need to adjust the algorithm for that.
:
: After this you need to get the remainder of above expression:
:
: N add spaces = (WIDTH - SUM OF ALL WORDS LENGTH) % (WORD COUNT - 1);
:
: After all these preparations are done - you can justify text:
:
: // pseudocode:
: while (more words left)
: {
: output next word
: if (that was last word)
: {
: break;
: }
:
: BLANKS = N spaces
: if (N add spaces != 0)
: {
: BLANKS++; N add spaces--;
: }
: output BLANKS number of spaces
: }
:
:
:
:
:
hello sir, please compile this code the watch the output, the programs seems working, but their is a big problem, the program devides the word. the program should not devide it, please take a look at the programm and correct it, i really need some help on this, cuz this programm really makes me crazy. and look at this photos:
http://img381.imageshack.us/my.php?image=output16km.jpg
http://img394.imageshack.us/my.php?image=output26kl.jpg
the program's output should be like in that photos, hope for you help dear guys.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void ruler(int SIZE, char a[]);
int main()
{
char c[]="We cant process trade into life without advertising. Advertisements are the most important things for trade. When we want to sell a product with a great benefit, we introduce our product to the customers by using the words such as 'the best, the dazzled, the impressive', and we use advertisements to effect the customers.";
int scanSize;
printf("Enter a text size: ");
scanf("%d",&scanSize);
printf("\n");
ruler(scanSize,c);
printf("\n");
return 0;
}
void ruler(int SIZE, char a[])
{
int i=0,j, hold;
while(a[i]!='\0'){
printf("%c",a[i]);
if((i+1)%SIZE==0){
hold=i;
while((a[i]!=' '&&a[i+1]!=' ')){
i=i-1;
}
printf("\n");
i=hold;
}
i++;
}
}