- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将整数的 txt 文件传递到smallest_xcoord 结构中。我正在尝试获得凸包。我的问题是,我在尝试时不断收到错误。如何将从文本文件读取的整数传递到我的结构函数中?我没有包含我的 struct Point 但它存储了一个 int x;和 int y; (对于凸包点)。
```
//GLOBAL Variable
static int integers[100000];
int load_integers(const char* filename)
{
//int integers[100000];
FILE *fp = NULL;
int value;
int i = -1;
if ((fp= fopen (filename, "r"))==NULL)
{
return -1;
}
while (fscanf (fp, "%u", &value)&& !feof(fp) && ++i <100000)
{
integers[i] = value;
}
fclose(fp);
return i+1;
}
struct Point smallest_xCoord (struct Point points, int numPoints)
{
struct Point points[];
struct Point minX_point = points[0];
int i;
for(i=1;i<numPoints;i++)
{
if ((points[i].x) < (minX_point.x))
{
minX_point = points[i];
}
else if (points[i].x == minX_point.x)
{
if (points[i].y < minX_point.y)
{
minX_point=points[i];
}
}
}
return minX_point;
}
int main(int argc, char *argv[])
{
int num_ints=0;
if (argc <2)
{
fprintf(stderr, "%s <file>\n",argv[0]);
return -1;
}
if ((num_ints = load_integers(argv[1])) <=0)
{
fprintf(stderr, "Error reading from file: %s\n",argv[1]);
return -1;
}
smallest_xCoord(integers, num_ints);
return 0;
}
```
最佳答案
smallest_xCoord(整数, num_ints);
首先,您不能将整数数据类型传递给“Point”数据类型参数。其次,您不能将数组整数数据类型传递给单个 Point 参数。
struct Pointsmallest_xCoord(structPointpoints,intnumPoints) { struct Point点[];
第三,您无法在 x_Coord 内部创建与其参数名称相似的新变量,因为您要重新声明它。
如果你想传递一个数组作为参数,你必须在它的名字之前使用一个指针(*)。为了使smallest_xCoord函数起作用,您需要指定要比较或分配给Point结构的哪个成员。我给您的建议是,您可能需要将该全局 int 数组变量更改为全局 Point 数组变量,并使用文件中的值加载它,我假设该文件应该包含 x 和 y 坐标的值,以便您可以比较加载的全局值将数组指向您提供的数组。然后,将smallest_xCoord 的参数更改为“struct Point *points”或“struct Pointpoints[]”,因为您要传递要比较的数组。
关于c - 如何将从文本文件读取的整数传递到结构函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60132194/
C语言sscanf()函数:从字符串中读取指定格式的数据 头文件: ?
最近,我有一个关于工作预评估的问题,即使查询了每个功能的工作原理,我也不知道如何解决。这是一个伪代码。 下面是一个名为foo()的函数,该函数将被传递一个值并返回一个值。如果将以下值传递给foo函数,
CStr 函数 返回表达式,该表达式已被转换为 String 子类型的 Variant。 CStr(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CSng 函数 返回表达式,该表达式已被转换为 Single 子类型的 Variant。 CSng(expression) expression 参数是任意有效的表达式。 说明 通常,可
CreateObject 函数 创建并返回对 Automation 对象的引用。 CreateObject(servername.typename [, location]) 参数 serv
Cos 函数 返回某个角的余弦值。 Cos(number) number 参数可以是任何将某个角表示为弧度的有效数值表达式。 说明 Cos 函数取某个角并返回直角三角形两边的比值。此比值是
CLng 函数 返回表达式,此表达式已被转换为 Long 子类型的 Variant。 CLng(expression) expression 参数是任意有效的表达式。 说明 通常,您可以使
CInt 函数 返回表达式,此表达式已被转换为 Integer 子类型的 Variant。 CInt(expression) expression 参数是任意有效的表达式。 说明 通常,可
Chr 函数 返回与指定的 ANSI 字符代码相对应的字符。 Chr(charcode) charcode 参数是可以标识字符的数字。 说明 从 0 到 31 的数字表示标准的不可打印的
CDbl 函数 返回表达式,此表达式已被转换为 Double 子类型的 Variant。 CDbl(expression) expression 参数是任意有效的表达式。 说明 通常,您可
CDate 函数 返回表达式,此表达式已被转换为 Date 子类型的 Variant。 CDate(date) date 参数是任意有效的日期表达式。 说明 IsDate 函数用于判断 d
CCur 函数 返回表达式,此表达式已被转换为 Currency 子类型的 Variant。 CCur(expression) expression 参数是任意有效的表达式。 说明 通常,
CByte 函数 返回表达式,此表达式已被转换为 Byte 子类型的 Variant。 CByte(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CBool 函数 返回表达式,此表达式已转换为 Boolean 子类型的 Variant。 CBool(expression) expression 是任意有效的表达式。 说明 如果 ex
Atn 函数 返回数值的反正切值。 Atn(number) number 参数可以是任意有效的数值表达式。 说明 Atn 函数计算直角三角形两个边的比值 (number) 并返回对应角的弧
Asc 函数 返回与字符串的第一个字母对应的 ANSI 字符代码。 Asc(string) string 参数是任意有效的字符串表达式。如果 string 参数未包含字符,则将发生运行时错误。
Array 函数 返回包含数组的 Variant。 Array(arglist) arglist 参数是赋给包含在 Variant 中的数组元素的值的列表(用逗号分隔)。如果没有指定此参数,则
Abs 函数 返回数字的绝对值。 Abs(number) number 参数可以是任意有效的数值表达式。如果 number 包含 Null,则返回 Null;如果是未初始化变量,则返回 0。
FormatPercent 函数 返回表达式,此表达式已被格式化为尾随有 % 符号的百分比(乘以 100 )。 FormatPercent(expression[,NumDigitsAfterD
FormatNumber 函数 返回表达式,此表达式已被格式化为数值。 FormatNumber( expression [,NumDigitsAfterDecimal [,Inc
我是一名优秀的程序员,十分优秀!