79736074

Date: 2025-08-15 04:05:18
Score: 3.5
Natty:
Report link

[…] I'm stuck in trying to split the line into string and real, […]

As you probably know, Pascal’s built‐in procedures read/readLn can read multiple data at once by specifying multiple destination variables. However, if you specify a string variable, such a destination variable is filled to the brim, i. e. possibly reading digits, too, or not reading enough name letters.

[…] I can't find anything on the net and hope you could help me. […]

Programming involves intuition that cannot be taught in textbooks. Here you are supposed to realize that it is not necessary to “split” the line into components. You do not re‐use, check on previously read names as you go through the file. (You would need to store the names if your task was, say, to also sort names alphabetically.)

Instead, you pass the names through as is. This can be achieved in the following way. Remember that valid number literals that can be read start with decimal digits, possibly preceded by a sign. Since digits or signs do not appear in names, you can use this circumstance as your criterion whether a name has been read completely or not.

program splittingLineIntoRealAndStrings(input, output);
    var
        { Replace the names `x`, `y` as appropriate. }
        x, y, product, total: real;
    begin
        { Discard the number of lines datum. Use `EOF`‐check instead. }
        readLn(total);
        { Initialize running total to zero. }
        total ≔ 0;
        
        { `EOF` is shorthand for `EOF(input)`. }
        while not EOF do
        begin
            { First we just copy everything until the first digit or sign. }
            while not (input↑ in ['0'‥'9', '+', '−']) do
            begin
                output↑ ≔ input↑;
                put(output);
                { Note that `get` does not consume the next character.
                  This is important so the following `readLn(x, y)` has
                  the opportunity to inspect the sign or first digit. }
                get(input)
            end;
            
            readLn(x, y);
            product ≔ x * y;
            { To disable scientific notation (`…E…`)
              you need to supply two format specifiers. }
            writeLn(product:1:2);
            { Finally, keep tab of the running `total`. }
            total ≔ total + product
        end;
        writeLn(total:1:2)
    end.

I know that this language [has] died a couple of years ago, […]

On the contrary, – a dialect of Pascal notable for its OOP extensions – keeps appearing in the StackOverflow’s Developer Survey results. There are real‐life applications, developers get paid to program in Delphi. The FreePascal Compiler is an open‐source project that attempts to be compatible to Delphi, the latest stable version having been released in 2021. Its sister project Lazarus provides an IDE and Delphi‐compatible components.

Reasons:
  • Blacklisted phrase (1): help me
  • Blacklisted phrase (1): StackOverflow
  • Whitelisted phrase (-1.5): you can use
  • RegEx Blacklisted phrase (1.5): I'm stuck
  • RegEx Blacklisted phrase (3): you could help me
  • Long answer (-1):
  • Has code block (-0.5):
Posted by: Kai Burghardt