2015-04-06 5 views
0

Obtenir Type expression list treated as compound expression in initializer Sur ces deux appels de fonction -Setenv: liste d'expression est Type traité comme une expression composé dans initialiseur

char itoa(new_total, new_total_ch, 10); 
    int setenv("COUNT_TOTAL", new_total_ch, 1); 

est ici l'extrait de code -

#include <iostream> 
// create process team 
#include <stdio.h> 
#include <unistd.h> 
#include <stdlib.h> 
#include <sys/types.h> 
#include <sys/wait.h> 
#include <ctime> 
// initialize & process 
#include <time.h> 
#include <string> 
#include <fstream> 
#include <cmath> 
#include <iosfwd> 
// initialize & process 
using std::ifstream; 
using namespace std; 

class Count3sProcessParallel { 

public: 
    //int process(); 
    int pr_count; 
    int process(); 
    typedef int COUNT_TOTAL; 


private: 

    int worker; 
    //declare process() 
    long unit_of_work; 
    long lower_bound; 
    long upper_bound; 
    int pr_i; 
    char * ct; 
    int ct_i; 
    int new_total; 
    char itoa(); 
    char * new_total_ch; 
    int setenv(); 

}; 


int Count3sProcessParallel::process() { 
    // determine upper lower bounds 
    unit_of_work = in_length/workers_num; 
    lower_bound = (worker -1) * unit_of_work; 
    upper_bound = (worker * unit_of_work) -1; 

    // iterate and count 
    pr_count = 0; 
    for (pr_i = lower_bound; pr_i < upper_bound; pr_i++) 
     if (floor(in_buffer[pr_i] == 3)) 
     pr_count++; 
     return pr_count; 

    //update COUNT_TOTAL 
    ct = getenv("COUNT_TOTAL"); 
    ct_i = atoi(ct); 
    new_total = (pr_count + ct_i); 
    char * new_total_ch[33]; 
    char itoa(new_total, new_total_ch, 10); 
    int setenv("COUNT_TOTAL", new_total_ch, 1); 

    delete[] in_buffer; 
    return 0; 
} 

Comment puis-je résoudre ce problème? Merci.

+0

Qu'essayez-vous de faire avec 'char itoa (new_total, new_total_ch, 10);'? Au début, je dirais que vous avez été frappé par l'analyse la plus vexante, mais votre question dit que vous essayez d'appeler une fonction. Pourquoi lancerais-tu le 'char' alors? – Pradhan

+0

@Pradhan - setenv prend "nom" et "valeur" de type char. itoa convertit 'net_total' en' new_total_ch' qui est passé en tant que "valeur" par la fonction setenv. – basswaves

Répondre

1

Supprimez les types principaux. Il suffit d'utiliser:

itoa(new_total, new_total_ch, 10); 
setenv("COUNT_TOTAL", new_total_ch, 1); 
+0

Oui, ça l'a fait. Cela semble simple maintenant. Je vous remercie. – basswaves