im trying to run this program, it works, but i need the cursor to be directly after the last letter of text, and when i run it it ends up being about 7 spaces after the last letter. any help is greatly appreciatedCode:#include<stdio.h> #include<string.h> char line[100]; int i, n, len, width, gaps, spacestoshare, equalshare, extras; int main() { gaps=0; printf("Please enter the width of the column:"); scanf("%i", &width); fflush (stdin); printf("\nPlease enter a line of text"); gets (line); len = strlen (line); while (len>width) { printf("\nError, your line of text is too long, please re-enter a"); printf(" shorter line of text:"); gets (line); len = strlen (line); } for (i=0; i<=width; i++) { if (line[i]==' ') { gaps++; } } spacestoshare = width-len; equalshare = spacestoshare/gaps; extras = spacestoshare%gaps; for (i=0; i<=width; i++) { printf("%c", line[i]); if (line[i]==' ') { for (n=0;n<=equalshare;n++) { printf(" "); } if (extras!=0) { printf(" "); extras-=1; } } } }



LinkBack URL
About LinkBacks


