im trying to create a program that right justifies the text entered by the user.. i already figured how to justify the text i just dont know how to get out of the loop that i created .. here's my code :
Code:
#include<stdio.h>
#include<stdlib.h>
#define Maxlength 200

void justify(int x, char parag[Maxlength + 1]);

main()
{

      int length, ans;
      char text[Maxlength + 1];
      printf("Enter 1 to continue, any key to stop ");
      scanf("%d", &ans);
      while(ans == 1)
      {
         printf("Enter length of the line ");
         scanf("%d", &length);
         printf("Enter text:\n");
         justify(length, text);
         printf("\nEnter 1 to continue, any key to stop ");
         scanf("%d", &ans);
      }
}

void justify(int x, char parag[Maxlength + 1])
{

   int currlinelength = 0;
   int wordlength;
   while(scanf("%s", parag) != EOF)
   {
   for(wordlength = 0; parag[wordlength] != '\0'; wordlength++)
      ;
   if(wordlength > x)
      printf("\nERROR: word length exceeds line length");
   if(currlinelength == 0)
   {
      printf("%s", parag);
      currlinelength = wordlength;
   }
   else
   {
      currlinelength += wordlength + 1;
         if(currlinelength > x)
         {
            printf("\n%s", parag);
            currlinelength = wordlength;
         }
         else
            printf(" %s", parag);
   }
   }
}
first off i try to ask the user if they want to continue.. after the user is done entering the text, i try to ask them again if they want to continue, but the program just stops once it's done justifying the entered text. . i cant seem to figure out how to have that statement "Enter 1 to continue ...." to show up again.. does anyone know what the problem is ?? thanx in advance