2013-04-08 71 views
-4

我寫此代碼來置換任意數量和出現以下錯誤: 在函數「廉政的main()」: 無效使用無效表達這個c語言代碼有什麼問題?

#include <stdio.h> 
#include <stdlib.h> 

typedef unsigned long int uint; 
uint t[11],n; 

void permute(uint k) {  
    uint i,c; 

    if (1==k) {  
    for (i=n; i>0; --i) 

    printf("%d", t[i]); 
    printf("\n"); 
    } 
    else 
    {  
    permute(k-1); 
    for (i=1; i<k; ++i) 
    { 
     c=t[i]; t[i]=t[k]; t[k]=c;  
     permute(k-1);  
     c=t[i]; t[i]=t[k]; t[k]=c;} 
    } 
} 

void run(uint x) 
{  
    n=0; 
    while (x>0) 
    {  
     t[++n]=x%10;  
     x /= 10; 
    }  
    permute(n); 
} 

int main() 
{ 
    printf ("%d\n",run(125)); 
} 
+0

爲便於閱讀,請格式化! TIA – 2013-04-08 17:02:20

回答

3
printf ("%d\n",run(125)); 

您正在使用的返回值功能runrun返回任何

void run(uint x) 

void表示該功能沒有返回,

1

您聲明的運行時間爲void run(uint x),但您將它作爲參數傳遞給printf(),它將期望它返回一個整數值以匹配"%d\n"格式字符串。

0

run返回void並且當它沒有返回任何值時,您不能從函數run中「提取」整數。這是無效的。