【发布时间】:2012-03-30 09:54:03
【问题描述】:
作为 XCode 项目的一部分,我正在用 C 编写一些类似的程序。由于这个新程序需要展示一些与第一次工作迭代略有不同的功能,我认为目标是最好的使用方法。
所以我尝试创建一个新目标,并按照我认为正确的方式进行操作,从谷歌搜索如何(在 XCode 中)。但是在编译时,我得到了太多的错误。
这是我得到的错误屏幕:
我发现它存在大量不同字符的问题,所以我确定这可能是一个简单的问题,例如一些丢失的文件。但我不知道该谷歌什么,所以我希望我问的没问题。
在相关的说明中,有人知道为什么我的第一个版本的程序 main.c 不需要像上面那样包含头文件吗?
谢谢!
编辑: 下面是来自新目标的代码,它实际上与迄今为止未更改的程序的第一个版本相同:
/*
* ScalarProduct.c
* Concurrency_Practical1
*
* Created by Chucky on 11/03/2012.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#include "ScalarProduct.h"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
//the final answer
int finalScalarProd;
//random variable
int rand_seed=10;
int rand()
{
int n;
n = random()%11;
//printf("%d\n", n);
return(n);
}
void* getScalarProduct(void *arg)
{
//index for loop
int i;
//scalarProduct of 10 integers
int * scalarProd = (int *) arg;
//my two arrays
int list1[10];
int list2[10];
for (i=0; i<10; i++) {
list1[i] = rand();
list2[i] = rand();
*scalarProd += list1[i]*list2[i];
printf("%d:\t\t %d\t\t %d\t\t %d\t\t\n", i, list1[i], list2[i], list1[i]*list2[i]);
}
return((void*)scalarProd);
}
int main (int argc, const char * argv[]) {
// insert code here...
pthread_t t1, t2;
int sp1= 0, sp2 = 0;
printf("Index\t List1\t List2\t Product\n\n");
pthread_create( &t1, NULL, getScalarProduct, &sp1);
pthread_create( &t2, NULL, getScalarProduct, &sp2);
pthread_join( t1, NULL);
pthread_join( t2, NULL);
printf("\nScalar Products: %d %d\n", sp1, sp2);
finalScalarProd = sp1 + sp2;
printf("Result: %d\n", finalScalarProd);
return 0;
}
【问题讨论】:
-
说真的,如果您希望有人指出正确的方向,请将输出复制并粘贴到您的问题中。错误引用的相关代码也很好。
-
没有输出,因为它甚至不会编译。不知道它是代码的哪个特定部分,但它是一个小程序,所以我想我会把它全部粘贴到下面的编辑中^^^
-
@Chucky Brian 指的是编译器的错误消息 - 屏幕截图没有帮助,通常认为复制文本消息会更好。跨度>
-
我的意思是你发布的截图的输出。我怀疑如果您单击错误旁边的那些小箭头,它们会告诉您问题出在哪里。您缺少
;右括号,或其他一些导致混乱的简单语法错误(它是级联的)。 -
这个我也加一下,虽然很长
标签: c xcode build compilation header