ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have an error, which I have no idea why appears. All brackets seems ok.
error:
Code:
(20,17) Error: Illegal qualifier
(20,19) Fatal: Syntax error, ")" expected but "." found
Code:
1. program trans;
2.
type autobusai = record
3.
stot: string[20];
4.
marsrutas: integer;
5.
end;
6.
type masyvas1 = array [1..100] of autobusai;
7.
type masyvas2 = array [1..100] of integer;
8.
var a: masyvas1; atr, k: masyvas2; f: text; n, max: integer;
9.
10.
procedure skaitymas (var f: text; var n: integer; a: masyvas1; k: masyvas2);
11.
var i, j: integer;
12.
begin
13.
assign(f, 'U2.txt');
14.
reset(f);
15.
readln(f, n);
16.
for i:=1 to n do
17.
begin
18.
read(f, a[i].stot, k[i]);
19.
for j:=1 to k[i] do
20.
read(f, a[i][j].marsrutas); //n-stoteliu sk, k-marsrutu sk
21.
readln(f);
22.
end;
23.
close(f);
24.
end;
25.
26.
procedure atrinkimas (a: masyvas1; var atr, k: masyvas2; n: integer);
27.
var h, f, i, j: integer;
28.
begin
29.
for h:=1 to n do
30.
begin
31.
for f:=1 to k[i] do
32.
atr[a[h][f].marsrutas] := 0;
33.
end;
34.
35.
for i:=1 to n do
36.
begin
37.
for j:=1 to k[i] do
38.
atr[a[i][j].marsrutas] := atr[a[i][j].marsrutas] + 1;
39.
end;
40.
end;
41.
42.
function maximum (a: masyvas1; var atr, k: masyvas2; n: integer) : integer;
43.
var i, j: integer;
44.
begin
45.
maximum := atr[a[1][1].marsrutas];
46.
for i:=1 to n do
47.
begin
48.
for j:=1 to k[i] do
49.
begin
50.
if maximum < atr[a[i][j].marsrutas]
51.
then maximum := atr[a[i][j].marsrutas];
52.
end;
53.
end;
54.
end;
55.
56.
procedure rasymas (var f: text; max, n: integer; a: masyvas1; k: masyvas2);
57.
var i, j: integer;
58.
begin
59.
assign(f, 'U2rez.txt');
60.
rewrite(f);
61.
writeln(f, max);
62.
for i:=1 to n do
63.
begin
64.
for j:=1 to k[i] do
65.
begin
66.
if a[i][j].marsrutas = max
67.
then writeln(f, a[i].stot);
68.
end;
69.
end;
70.
end;
71.
72.
begin
73.
skaitymas(f, n, a, k);
74.
atrinkimas(a, atr, k, n);
75.
max := maximum(a, atr, k, n);
76.
rasymas(f, max, n, a, k);
77.
end.
Then use the "comment out" approach. I.e. start replacing procedure/function bodies with empty ones until the error disappears. The last emptied body will be the culprit.
When you find it, start restoring pieces of code until you realize which piece of code caused the error.
Asido, my Pascal is quite rusty, but looking at line 20 of your code it looks like it tries to assign a record of a two-dimensional array "a". But in the declaration scope the array is one-dimensional:
Code:
type autobusai = record
stot: string[20];
marsrutas: integer;
end;
type masyvas1 = array [1..100] of autobusai;
var a: masyvas1;
I interpret this as declaring an array of 100 elements, each of them being a record made of a string of maximum length 20 and an integer. If this is correct you cannot assign the following:
Please stop using "pastebin": you can post your code snippets directly into LQ (just remember to use code blocks.
In any case:
Code:
type
autobusai = record
stot: string[20];
marsrutas: integer;
end;
masyvas1 = array [1..100] of autobusai;
var
a: masyvas1;
* String is an array of char (just FYI: not relevant here one way or the other)
By default, it's variable length
"string[20]" is exactly 20 printable characters: no more, no less
* masyvas1 is an array of "autobusai" records
So:
Code:
read(f, a[i].stot); // This will read one string
'Hope that helps .. PSM
Last edited by paulsm4; 04-29-2010 at 04:59 PM.
Reason: Correction
read(f, a[i].marsrutas[j]); // This will read one string
Paul, the field "marsrutas" is a scalar integer and it can't accept an index. Maybe the statement should assign the character array "stot", as you pointed out. Anyway, I don't understand what's the intent of this code, first because we don't know what is the content of the input file, second because... I cannot translate from Lithuanian!
Ok, so I'll better write what i actually need to do, since I am kinda confused with the code now. I need to make a program which reads U2.txt and picks the number which is repeated the most after the string and it should be written in the U2rez.txt. The U2.txt example:
Code:
5 {<--this number shows the amount of strings}
Rytas 5 1 2 5 4 6
Vakarai 3 12 5 4
Baltasis lokys 6 12 1 6 8 7 3
Panerys 1 12
Rudasis tiltas 3 8 14 4
{first number after the string shows the amount of numbers in the line}
In this example there are 2 such number - 4 and 12. In such case the smaller must be written.
Furthermore, the string must be typed in which this number is.
If I use the U2 example above, the U2rez should look like this:
Code:
4
Rytas
Vakarai
Rudasis tiltas
My code is in the first post. (sorry for using pastebin before)
Well, finally I managed to make it work. If someone is interested in code (have no idea why should be :P), here it is:
Code:
program trans;
type autobusai = record
stot: string[20];
atr, k, tikr: integer;
end;
type masyvas1 = array [1..100] of autobusai;
type masyvas2 = array [1..100,1..100] of integer;
var a: masyvas1; marsrutas: masyvas2; f: text; n, max: integer;
procedure skaitymas (var f: text; var n: integer; var a: masyvas1; var marsrutas: masyvas2);
var i, j: integer;
begin
assign(f, 'U2.txt');
reset(f);
readln(f, n);
for i:=1 to n do
begin
read(f, a[i].stot, a[i].k);
for j:=1 to a[i].k do
read(f, marsrutas[i][j]); //n-stoteliu sk, k-marsrutu sk
readln(f);
end;
close(f);
end;
procedure atrinkimas (var a: masyvas1; var marsrutas: masyvas2; n: integer);
var h, f, i, j: integer;
begin
for h:=1 to n do
begin
for f:=1 to a[h].k do
a[marsrutas[h][f]].atr := 0;
end;
for i:=1 to n do
begin
for j:=1 to a[i].k do
a[marsrutas[i][j]].atr := a[marsrutas[i][j]].atr + 1;
end;
end;
function maximum (var a: masyvas1; var marsrutas: masyvas2; n: integer) : integer;
var i, j, l, t, b, p: integer;
begin
maximum := a[marsrutas[1][1]].atr;
for i:=1 to n do
begin
for j:=1 to a[i].k do
begin
if maximum < a[marsrutas[i][j]].atr
then maximum := a[marsrutas[i][j]].atr;
end;
end;
p := 1;
for l:=1 to n do
begin
for t:=1 to a[l].k do
begin
if a[marsrutas[l][t]].atr = maximum
then
begin
a[p].tikr := marsrutas[l][t];
p := p + 1;
end;
end;
end;
maximum := a[1].tikr;
for b:=2 to p do
begin
if a[b].tikr < maximum
then a[b].tikr := maximum;
end;
end;
procedure rasymas (var f: text; max, n: integer; a: masyvas1; marsrutas: masyvas2);
var i, j: integer;
begin
assign(f, 'U2rez.txt');
rewrite(f);
writeln(f, max);
for i:=1 to n do
begin
for j:=1 to a[i].k do
begin
if marsrutas[i][j] = max
then writeln(f, a[i].stot);
end;
end;
close(f);
end;
begin
skaitymas(f, n, a, marsrutas);
atrinkimas(a, marsrutas, n);
max := maximum(a, marsrutas, n);
rasymas(f, max, n, a, marsrutas);
end.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.