Qos*_*smo 2 c struct pointers dynamic
struct aPoint {
int somaVertical;
int somaHorizontal;
int valor;
};
Run Code Online (Sandbox Code Playgroud)
我有一个在main()中动态创建的结构数组,如下所示:
struct aPoint *ps = malloc( sizeof(struct aPoint) * columns * rows )
Run Code Online (Sandbox Code Playgroud)
我想在一个函数中使用main()之外的struct值sscanf().数组的初始化也照顾在主的().
我怎样才能通过该结构的数组,通过该功能,并设置一些结构值藏汉呢?唉,我讨厌指针!
谢谢!
那将是:
int readStuff(struct aPoint *ps, size_t len, const char *someVar)
{
unsigned int i;
for (i = 0; i < len; i++) {
sscanf(someVar, "%d", &(ps[i].somaVertical));
/* And so on for the other fields */
}
/* Return whatever you're returning here */
}
const size_t len = colunas * linhas;
struct aPoint *ps = calloc(len, sizeof(struct aPoint));
int success = readStuff(ps, len, arrayOfNumbers);
Run Code Online (Sandbox Code Playgroud)