2017-10-19 189 views
-3

我有一個prinf函數列表,我想知道如何遍歷它們。迭代printf列表

#include <stdio.h> 


void N() 
{ 
    int count; 
    count += count; 
} 

int main() 

{ 
    int pfReturnCount = 0; 

    pfReturnCount = printf("#####.00000000000.......00000...00000#### \n"); 
    pfReturnCount = printf("#####..000.....000......000000...000.#### \n"); 
    pfReturnCount = printf("#####..000.....000......000.000..000.#### \n"); 
    pfReturnCount = printf("#####..0000000000.......000..000.000.#### \n"); 
    pfReturnCount = printf("#####..000.....000......000...000000.#### \n"); 
    pfReturnCount = printf("#####..000.....000......000....00000.#### \n"); 
    pfReturnCount = printf("#####.00000000000......00000...00000.#### \n"); 

    N(pfReturnCount); 
    printf("data value after calling the N funtion is %d\n",pfReturnCount); 

    return (0); 
} 

我把它給我的第一個printf的價值,但我不知道如何通過整個列表循環,所以我可以總結我的字符在所有的printf函數的總數。

回答

0

只需更換=與+ =

#include <stdio.h> 


void N() 
{ 
    int count; 
    count += count; 
} 

int main() 

{ 
    int pfReturnCount = 0; 

    pfReturnCount += printf("#####.00000000000.......00000...00000#### \n"); 
    pfReturnCount += printf("#####..000.....000......000000...000.#### \n"); 
    pfReturnCount += printf("#####..000.....000......000.000..000.#### \n"); 
    pfReturnCount += printf("#####..0000000000.......000..000.000.#### \n"); 
    pfReturnCount += printf("#####..000.....000......000...000000.#### \n"); 
    pfReturnCount += printf("#####..000.....000......000....00000.#### \n"); 
    pfReturnCount += printf("#####.00000000000......00000...00000.#### \n"); 

    N(pfReturnCount); 
    printf("data value after calling the N funtion is %d\n",pfReturnCount); 

    return (0); 
} 
0

可以每行推到一個字符串數組,然後簡單地得到陣列中的每個元件的長度。