Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i have to make this program, but i still haven't finished it and i need some help. This is what i have to do. Make a program in Pascal that after has read a text with a list of nums., it will return the numb. of the nums that appear less than one times in the text.

The text that will be read from the program should be like that.

In the first line there are two nums. seperated by a space, n and m. N is the number of nums that exist, like if the text contains the numbers 1,2,3,4, n is 4 (1..n). M is how many lines follow. Every line has a couple of nums, a,b, (1=b) a and b are separated by a space.

The file that the program will make will have written on it a num., that says how many nyms are appeared less than two tims in the text.

All the nums. are Integer.

0=


i've made the following program, but it only reads the first line of the text. Anyone that can help me? The deadline is almost ended. Thanks in advance. My code is the following.


I've made the code after that, the program is how to put into variables all the nums. I'm a beginner so if anyone could give me an example, would help a lot.
Example of the text that reds.
domes.in
6 7
2 4
4 1
3 5
4 3
1 3


Pascal
Program thefinalp;
  Uses SysUtils;
        
  Var
    f:Text;
    m,d:Integer;
    n:Char;
    c:String[1];
        
    a,e:array of integer;
    LowArr:Integer;
    HighArr:Integer;
    ArrayLen:Integer;
    i:Integer;
        
        
    begin
      Assign(f,'finalp.txt');
      Reset(f);
        
      repeat
        Read (f,n);
        Write(n);
      until (n=' ');
        
      Read(f,c);
      Write(c);
        
      readln(f,d);
      Writeln(d);
        
      StrToIntDef(n,m);
        
      setlength(a,m);
      LowArr:=Low(a);
      HighArr:=High(a);
      ArrayLen:=Length(a);
        
      setlen;
      LowArr:=Low(e);
      HighArr:=High(e);
      ArrayLen:=Length(e);
        
      for i:= LowArr to HighArr do
      begin
        repeat
          Read (f,a[i]);
          Write(a[i]);
        until (n=' ');
            
        Read(f,c);
        Write(c);

        readln(f,e[i]);
        Writeln(e[i]);
        
      End;

      Readln;
    End.


[edit]Code indentation added - OriginalGriff[/edit]
[edit]Fixed pre tag - Matt T Heffron[/edit]
Posted
Updated 28-Jan-14 4:55am
v16

1 solution

Because seekEoln[^] returns true if it is at the end of a line. Which it won't be the first time you enter the loop in your sth procedure, but will be immediately after calling readln...

And please, do yourself a favor: learn to indent your code so it is at least partly readable? It'll make your life a lot easier in the future, as well as our now... :sigh:
 
Share this answer
 
Comments
Member 10538783 26-Jan-14 4:57am    
Thank you for the comments.I tried to indent my code a little beat, i hope it's better now. Em, about the seekEoln, do you mean that i shouldn't put readln but read? Although i'm not sure that this is what you meant.
OriginalGriff 26-Jan-14 5:24am    
I've manually indented the code for you - and if you look closely the indentation reveals a bug: look at the "if eof..." line near the bottom - can you see a problem?
Easier to follow what is going on like that? :)

You are using seekEOLn as part of your loop check - so as soon as you are at the end of a line, the loop will exit. Perhaps you don't need it at all? Just the eof test?
Member 10538783 27-Jan-14 11:59am    
Thanks for indenting my code, it's really clearer now what's is written. Now, about the eoln, i tried not to use it, but the last characters of the line are put together with other nums., into the same variable. The problem is that it must be in one variable isolated. Is there sth i could do?
OriginalGriff 27-Jan-14 12:26pm    
Are you sure?
http://www.freepascal.org/docs-html/rtl/system/readln.html
Note:
"The end-of-line marker is not considered part of the line and is ignored."
Could it be that the Writeln is making it look like it is?
Member 10538783 27-Jan-14 12:43pm    
Yes you're right the seekeoln shouldn't be the problem, i erased it and i corrected to the code there is under my question, but it still doesnt't work, is it possibly because of StrToIntDef(n,m)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900