所以我是SO的新手,我的问题没有得到很好的回复......所以我编辑它以提供更多信息。
我正在尝试编写一个在主程序中调用两个函数的程序。这就是我到目前为止所做的:
#include <stdio.h>
#define N 10
int inner_product(int a[], int b[], int n);
int inner_product_reverse(int a[], int b[], int n);
int main(void) {
int a[N], b[N], i;
printf("Enter the first array of size 10: ");
for (i = 0; i < N; i++)
scanf("%d", &a[i]);
printf("Enter the second array of size 10: ");
for (i = 0; i < N; i++)
scanf("%d", &b[i]);
printf("Inner product is: %d\n", inner_product);
printf("Inner product reverse is: %d\n", inner_product_reverse);
return 0;
}
int inner_product(int a[], int b[], int n) {
int sum = 0, i;
for (i = 0; i < N; i++)
sum += (a[i] * b[i]);
return sum;
}
int inner_product_reverse(int a[], int b[], int n) {
int sum = 0, i;
for (i = 0; i < N; i++)
sum += (a[i] * b[(N-1)-i]);
return sum;
但我在标题中收到错误。我知道这是一个被调用的参数数量不同的问题,但我不知道如何以考虑函数的所有参数的方式编写它。 我是否必须以某种方式将计算内部产品的for循环移动到主体中?感谢。
答案 0 :(得分:0)
问题在于调用{
"id": "1",
"name": "banner1",
"status": "1",
"display_from": null,
"display_to": null,
"img_type": "1",
"img_file": "https://192.168.1.11/magento2/pub/media/ewl_bannerslider/slides/5.jpg",
"img_url": "",
"img_title": "banner1",
"img_alt": "banner1",
"url": "",
"is_open_url_in_new_window": "1",
"is_add_nofollow_to_url": "1"
},
{
"id": "5",
"name": "banner5",
"status": "1",
"display_from": null,
"display_to": null,
"img_type": "2",
"img_file": "https://192.168.1.11/magento2/pub/media/ewl_bannerslider/slides/",
"img_url": "https://www.dtelepathy.com/blog/wp-content/uploads/2015/06/Technique-for-Faster-Web-Development.jpg",
"img_title": "",
"img_alt": "",
"url": "",
"is_open_url_in_new_window": "1",
"is_add_nofollow_to_url": "1"
}
func bannerDownloadJsonWithURL(){
let url = URL(string: bannerUrl)!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if error != nil { print(error!); return }
do {
if let jsonObj = try JSONSerialization.jsonObject(with: data!) as? [[String:Any]] {
for item in jsonObj {
if let itemDict = item as [String:Any]! {
for item in itemDict {
if item.key["img_type"] == 1 {
}
}
}
}
DispatchQueue.main.async {
}
}
} catch {
print(error)
}
}
task.resume()
}
函数作为警告已经说过。
printf
printf("Inner product is: %d\n", inner_product);
printf("Inner product reverse is: %d\n", inner_product_reverse);
和inner_product
是返回int并接受3个参数的函数:inner_product_reverse
。
现在获取int结果,调用这两个函数。你做的是你将它们的指针(位置)传递给printf函数,这是错误的。
您应该将代码重写为类似的内容:
int (*)(int *, int *, int)