【发布时间】:2018-12-04 20:08:37
【问题描述】:
所以我的问题有点烦人。我必须创建一个名为 vector 的结构,它包含一个字符串 ~ 字符数组。供以后使用。到目前为止我写了什么:
vector.h
// forward declare structs and bring them from the tag namespace to the ordi$
typedef struct Vector Vector;
// actually define the structs
struct Vector {
int SortPlace;
char LineContent[100];
};
vector.c
// Initialize a vector to be empty.
// Pre: v != NULL
void Vector_ctor(Vector *v) {
assert(v); // In case of no vector v
(*v).SortPlace = 0;
(*v).LineContent[100] = {""};
}
我的错误信息是:
vector.c: In function ‘Vector_ctor’:
vector.c:13:24: error: expected expression before ‘{’ token
v->LineContent[100] = {""};
由于我是 C 编程新手,我有点迷路了。基本上我想创建一个没有内容的向量。
任何帮助将不胜感激。 问候
【问题讨论】:
-
(*v).foo~>v->foo((*v).foo没有错,但是读起来很别扭) -
在
vector.c:#include "vector.h" -
in
vector.h将您的代码包含在#ifndef VECTOR_H_INCLUDED换行符#define VECTOR_H_INCLUDED和#endif中。见Why include guards? -
嗨 Swordfish,我已经包含了 vector.h 并附上了我的代码.. 没有在代码中显示它,因为我很确定它不是错误
-
(*v).LineContent[100] = {""};===>(*v).LineContent[0] = 0;