「在此任務中鍛鍊,你需要創建libsolution.so其實現與以下原型功能的共享動態庫:一種用於C + Linux的
int stringStat (const char * string, size_t multiplier, int * count);
該函數返回的字符串值的長度乘以乘數,並增加1的值,表示計數。「
我的代碼:
#include <stdio.h>
unsigned strln(const char *str)
{
unsigned int len = 0;
while(*str!='\0')
{
str++;
len++;
}
return len;
}
int stringStat(const char *string, int multiplier, int *count)
{
*count = *count+1;
return strln(string)*multiplier;
}
int main(void) {
printf("%d", stringStat("hello", 2, 2));
return 0;
}
錯誤與線18-21:
相似之處@ Debian的GNU Linux的-8:〜/實驗室/ $ lab1中的gcc -o解決方案solution.c -c solution.c:在函數'main'中: solution.c:19:38:warning:通過'stringStat'的參數3傳遞參數3使得整型指針沒有轉換 printf(「%d」,stringStat(「hello 「,2,2)); ^ solution.c:12:5:注:預期 '詮釋*',但參數的類型 'INT' INT stringStat(常量字符*字符串,整數乘數,INT *計數){
誤差不用線路18-21:
我用-c選項,其工作編譯,但是當你嘗試啓動./solution舉報某些原因拒絕「權限」,糾正了文件模式,現在在這裏:
parallels @ debian-gnu-linux-8:〜/ labs/lab1 $ ./solution bash: ./solution:不能執行二進制文件:執行格式錯誤
我在這裏讀了很多的信息,我明白指針和宣稱的問題,但我不知道下一步該怎麼做。 它有點難,請給我一些答案的例子,plz。
你傳入'2'(A值)'stringStat'功能'INT * count' ......這是完全錯誤的。你應該開始學習一些關於pionters的東西 – LPs
你使用了'-c',所以gcc將生成一個對象文件而不是可執行文件。 – Ryan
注意:'strln'返回一個'unsigned' int,而'stringStat'返回一個int。 – LPs