>but i need the cursor to be directly after the last letter of text
Are you left justifying or right justifying? Your code says left, and that means that the spaces will be on the right side of the output. If you want to right justify then you'll have spaces on the left side of every word, which requires a slightly different algorithm:
Code:
/* Bad code. Use at your own peril */
#include<stdio.h>
#include<string.h>
char line[100];
char *t;
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;
if (++gaps == 0) {
equalshare = spacestoshare;
extras = 0;
}
else {
equalshare = spacestoshare/gaps;
extras = spacestoshare%gaps;
}
for (t=strtok (line, " "); t!=NULL; t=strtok (NULL, " ")) {
for (n=0;n<equalshare;n++) {
printf(" ");
}
if (extras!=0) {
printf(" ");
extras-=1;
}
printf ("%s", t);
}
printf("\n");
return 0;
}
>we have been told to use fflush so i will thank you very much
You should be more selective in who you follow orders from. Your teacher is stupid, and we will continue to nag you about it when you post code like that.