title: How to split a phrase into words in pascal?
body: <p>I have to create a program that splits phrases (with special characters such as % and $) into words using a procedure in pascal.</p>
  
  <p>So if i enter:</p>
  
  <pre><code>This is a valid word: 12$%ab
  </code></pre>
  
  <p>The program must return me:</p>
  
  <pre><code>This
  is
  a
  valid
  word:
  12$#ab
  </code></pre>
  
  <p>Without the spaces, one below the other.</p>
  
  <p>I can't use arrays and the variable that "calls" the procedure must be a string.</p>
  
  <p>Thanks in advance!</p>
  
  <p>Here's my code:</p>
  
  <pre><code>program words;
  uses crt;
  var 
   phrase  :string;
   word:string;
   letter  :char;
   x      :integer;
  
  begin
   clrscr;
   phrase:='';
   word:='';
   x:=1;                         
   repeat
    write('type a phrase: ');
    readln(phrase);
    until phrase&lt;&gt;'';
   while x&lt;=length(phrase) do
   begin
    letter:=phrase[x];
    case letter of
     'a'..'z','A'..'Z':
      begin
       word:=word+letter;
       repeat
         x:=x+1;
         letter:=phrase[x];
         word:=word+letter;
        until (letter=' ') or (x=length(phrase));
       writeln(word);
       word:='';
      end;
    end;
    x:=x+1;
   end;
  writeln;
  readkey;
  end.
  </code></pre>