如果我希望对象在回发中保持不变,那么在ViewState中存储Object是个好主意吗?还有更好的想法吗?我担心ViewState的大小太大了......
typedef struct {
void *elems;//address of the memory block
int elemSize; //
int logicLen;//number of existing elements in vector
int allocLen;//allocated space for the vector
} vector;
static void InsertNumbers(vector *numbers, long n, long d)
{
long k;
long residue;
for (k = 0; k < d; k++) {
residue = (long) (((long long)k * (long long) n) % d);
VectorAppend(numbers, &residue);
}
}
void VectorAppend(vector *v, const void *elemAddr)
{
void *target=(char*)v->elems + (v->logicLen * v->elemSize);
if(v->logicLen==v->allocLen){
v->allocLen*=2;
v->elems=realloc(v->elems,v->allocLen*v->elemSize); …Run Code Online (Sandbox Code Playgroud) 执行main,它会要求输入.
将输入存储在argbuf中.
然后,使用strwrd将argbuf拆分为标记
然而,它说"错误:将char*分配给char [200]的不兼容类型"
我无法弄清楚为什么..
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char argbuf[200];//used to store input
char *strwrd(char *s, char *buf, size_t len, char *delim){
s += strcspn(s, delim);
int n = strcspn(s, delim); /* count the span (spn) of bytes in */
if (len-1 < n) /* the complement (c) of *delim */
n = len-1;
memcpy(buf, s, n);
buf[n] = 0;
s += n;
return (*s == 0) ? NULL : s;
}
int main(){
fgets(argbuf, sizeof(argbuf), …Run Code Online (Sandbox Code Playgroud)