我在C編寫一些類似的程序作爲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;
}
嚴重的是,如果您希望某人指引您朝向正確的方向,請將輸出複製並粘貼到您的問題中。錯誤引用的相關代碼也會很好。 – 2012-03-13 23:01:52
沒有輸出,因爲它不會編譯。不知道它是哪個特定部分的代碼,但它是一個小程序,所以我想我會把它粘貼在下面的編輯^^^ – Chucky 2012-03-13 23:03:24
@Chucky布賴恩指的是編譯器的錯誤消息 - 截圖不*有用* ,通常認爲複製文本消息更好。 – Till 2012-03-13 23:05:42