读取两个连续的整数及其权重
我有一个从文件中读取整数的程序,如下所示。
value1 和 value2 将从用户处获取。
路径文件包含路径的权重,假设路径1到3的权重是4,路径5到6的权重是3,那么路径文件将是:
path
1 3 4
5 6 1
3 2 1
代码是:
fp=fopen("path","r");
while(fscanf(fp,"%d",i)==1)
{
if(((j==value1)&&(i==value2))||((j==value2)&&(i==value1)))
weight={next value which will be read};
}
我希望逻辑读取上述权重
另外,在扫描文件时它不应采用每行的第三个整数。
例如,如果我想要 1 到 3 之间的路径,那么它不应该扫描第三列中的 1 或 3。
提出这个疑问是相当困难的,但如果你们中有人愿意帮助我,我会尽力弄清楚。
I have a program which reads a integer from a file, as given below.
value1 and value2 are to be taken from user.
path file contains the weight of path, lets say weight of path 1 to 3 is 4 and 5 to 6 is 3, then path file will be:
path
1 3 4
5 6 1
3 2 1
The code is:
fp=fopen("path","r");
while(fscanf(fp,"%d",i)==1)
{
if(((j==value1)&&(i==value2))||((j==value2)&&(i==value1)))
weight={next value which will be read};
}
I want the logic to read the above weight
Also, while scanning the file it should not take the third integer of each line.
For example, if I want path between 1 to3 then it should not scan the 1 or 3 which is in third coloum.
The framing of this doubt is quite difficult, but I will try to make it clear if anybody of you wish to help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是C语言专家,但是函数fscanf的第三个参数需要一个内存地址,如果变量i是一个整数,你需要使用&i好吗?
http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/
我很抱歉,因为任何事情。哈哈 。
I'm not a expert in C language but the third parameter of the function fscanf expected a memory address, if the variable i is a integer, you need to use &i ok?
http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/
I'm sorry because for anything. lol .