描述:
我有一个遵循以下格式的文件:number number number
,这里有几行:
0 00 19
0 900000 949999
0 9500000 9999999
1 00 09
2 00 19
2 200 349
2 35000 39999
2 900000 949999
2 9500000 9999999
3 00 02
3 7000 8499
3 9500000 9999999
4 00 19
4 7000 8499
80 00 19
80 900000 999999
81 00 19
81 900000 999999
82 990000 999999
83 7000 8499
958 95000 99999
959 7000 8499
960 85000 99999
961 00 19
第一列代表区域
,第二列代表num1
和num2
。
我已经成功地将每一列存储在其各自的变量中:
int isRegistered(FILE* fp, int area)
{
int finished = 1;
int scanned_area;
char num1[7], num2[7];
int rc = 1;
rewind(fp);
while (finished != EOF) {
finished = fscanf(fp,"%d %s %s\n", &scanned_area, &num1, &num2);
}
return rc;
}
我知道我“不应该使用 fscanf”并且不应该使用 %s
进行扫描,但这些是特定于分配的,我无法更改它们。
现在我将所有这些数字存储在各自的变量中,第一列数字存储在 scanned_area
中,第二列存储在 num1
中,第三列存储在 中num2
.
场景
我的面积值为 1。如何对其进行编码,以便当 Scand_area == 1 时,函数停止?
最佳答案
I have an area value of 1. How do I code it so that when scanned_area == 1, the function stops?
您可以使用 break
跳出循环:
while (condtion)
{
// some code
if (scanned_area == 1)
{
break;
}
}
关于c++ - 满足条件后如何终止函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14678920/