如何对数组赋值,每次赋值都调用函数,怎么让它追加,不会覆盖

如何对数组赋值,每次赋值都调用函数,怎么让它追加,不会覆盖,第1张

可以啊,如:

void func(int a[], int pos)

{

a[pos] = 8888

}

那就这样:

void func(int a[], int pos)

{

a[pos] = 8888

}

我大概明白了你的意思,看看这个:

#include "stdafx.h" //VS 预编译头文件,其他系统请删除

#include<stdio.h>

#include<stdlib.h>

//VS 2013 否决了 scanf 等函数,为了使用,加上下句。

//其他系统请删除

#pragma warning(disable:4996)

void func(int *parr, int *pos, int sz)

{

printf("输入 -1 结束本次输入:\n")

int c

for ()

{

if (*pos == sz)

{

printf("\n数组已满,不能再接收数据!\n")

break

}

scanf("%d", &c)

if (c == -1)

break

parr[*pos] = c

*pos += 1

}

}

//VS 主函数签名格式。其他系统请改变签名,如:

//int main()

int _tmain(int argc, _TCHAR* argv[])

{

#define ARRSIZE 10

int arr[ARRSIZE]

int pos = 0

while (pos <ARRSIZE)

{

func(arr, &pos, ARRSIZE)

}

for (int i = 0i <ARRSIZEi++)

printf("%d", arr[i])

printf("\n")

system("pause")//避免窗口一闪而退

return 0

}

设为全局就可以了

var addArray = new Array() //新建数组存储 选中或取消的复选框

 function addToArray(id) {  //此处id为复选框的id,动态生成的        

        addArray.push(id)

        alert(addArray.length)

    }

@file_put_contents( './' . date("Y-m-d") . ".log", date('Y-m-d H:i:s') . "  " . $mess . PHP_EOL, FILE_APPEND )

你在file_put_contents函数中添加参数FILE_APPEND


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11820901.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存