编译问题与数组有关。 [英] Problem with compilation that has to do with an array.

查看:88
本文介绍了编译问题与数组有关。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我一直在努力让程序成为一个程序,它将从文本文件中读取第一个数字。第一行,然后将执行某个程序,这意味着将读取其他nums的程序。进入数组,与第一个数值的次数一样多。这是我制作的程序,但编译器有错误。这可能是因为我没有为每个程序a输入i:= 1到n或i:= 1到100000吗?

有谁可以帮助我?

程序文件文本; 
Var
a:数组[1..100000]的整数;
b:整数的数组[1..100000];
c,d,i,j:整数;
f:文字;
程序。
开始
重复
读取(f,a [i]);
写(a [i]);
直到(a [i] ='');
结束;

程序......
开始
而不是seekEoln和eof(f)do
开始
read(f,j [i]);
写(j [i]);
结束;
结束;
程序程序;
thenum;
空间;
sth;

程序空间;
begin
重置(f);
读(f,c);
写(c);
结束;

begin
Assign(f,'textfile.txt');
重置(f);
重复
读取(f,n);
写(n);
直到(n ='');
结束;

读(f,c);
写(c);
而不是seekEoln和eof(f)do
开始
read(f,d);
写(d​​);
结束;
for i:= 1到n
theprogram;
关闭(f);
Readln;
结束。

解决方案

您应该报告确切的错误消息,以获得帮助。

我尝试用Free Pascal编译器编译它,得到:

 filetext.pas(12,13)错误:不兼容的类型:得到Char预期Int64
filetext.pas(19,10)错误:非法限定符
filetext.pas(20,9)错误:非法限定符
filetext.pas(24,1)致命:语法错误,BEGIN 预期,但标识符THENUM找到了









首次报错a 类型不匹配:你无法将整数与字符进行比较:

引用:

直到( a [i] ='');

你可以修复它,例如这种方式(如果它对你有意义的话)

直到(a [i] = -1); 







发生第二次(和第三次)错误,因为您使用的是整数一个数组。

Qu注意:

读取(f,j [i]);

写(j [i]);

你不能下标一个整数变量(需要一个数组)。 br $>




第四个错误: BEGIN 是必需的:你忘了把 BEGIN 紧接在

Quote:

程序theprogram;

线。

Hello, well i've been trying to make a program a program that will read from a text file the first num. of the firs line, and then will do a certain procedure, that means a procedura that will read the other nums. into arrays, as many times as the value of the first num is. This is the program i've made, but the compiler has errors. Is that possibly because i have not put in every procedure a for i:=1 to n do or for i:=1 to 100000 do?
Can anyone please help me?

Program filetext;
Var
a:array[1..100000] of integer;
b:array[1..100000] of integer;
c,d,i,j:Integer;
f:Text;
Procedure thenum ;
Begin
repeat
Read (f,a[i]);
Write(a[i]);
until (a[i]=' ');
End;

Procedure sth ;
begin
while not seekEoln and eof(f) do
begin
read(f,j[i]);
Write(j[i]);
end;
End;
Procedure theprogram;
thenum;
space;
sth;

procedure space;
begin
Reset(f);
Read(f,c);
Write(c);
end;

begin
Assign(f,'textfile.txt');
Reset(f);
repeat
Read (f,n);
Write(n);
until (n=' ');
End;

Read(f,c);
Write(c);
while not seekEoln and eof(f) do
begin
read(f,d);
Write(d);
end;
for i:=1  to n do
theprogram;
Close(f);
Readln;
End.

解决方案

You should report the exact error messages, on order to get help.
I tried to compile it with Free Pascal Compiler, getting:

filetext.pas(12,13) Error: Incompatible types: got "Char" expected "Int64"
filetext.pas(19,10) Error: Illegal qualifier
filetext.pas(20,9) Error: Illegal qualifier
filetext.pas(24,1) Fatal: Syntax error, "BEGIN" expected but "identifier THENUM" found





First error reports a type mismatch: you cannot compare integers to characters:

Quote:

until (a[i]=' ');

You could fix it, for instance this way (if it makes sense to you)

until (a[i]=-1);




Second (and third) error occurs because you are using an integer like an array.

Quote:

read(f,j[i]);
Write(j[i]);

You cannot subscript a integer variable (an array is required).


Fourth error: BEGIN is required: you forgot to put BEGIN immediately below the

Quote:

Procedure theprogram;

line.


这篇关于编译问题与数组有关。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆