c++ array error while executing -
when run program keep getting error. program still execute , run , display correct nymbers in terminal, need ouput file , put them on there. please new c++.
bash-3.2$ g++ -wall 1.cpp
1.cpp: in function 'std::string ip_calculation(std::string*, std::string, int)':1.cpp:71:1: warning: control reaches end of non-void function [-wreturn-type]
string ip_calculation(string ip[], string company_name, int total_ips) { string temp = ""; char buf[80]; char buf2[80]; if (total_ips != 0) { int uniqueip_count = total_ips; (int = 0; < total_ips; i++) { (int j = + 1; j < total_ips; j++) { if (strcmp(ip[i].c_str(), ip[j].c_str()) == 0) { if (strcmp(ip[i].c_str(), "") == 0) { continue; } ip[j] = ""; uniqueip_count--; } } } temp = print_array(ip); cout << company_name << " | number of visitor: " << total_ips << "| unique visitors: " << uniqueip_count << endl; //cout<<company_name<<" | number of visitor: "<<buf <<"| unique visitors: "<<uniqueip_count<<endl; cout << temp; sprintf(buf, "%d", total_ips); sprintf(buf2, "%d", uniqueip_count); // return temp=company_name+" | number of visitor: "+( total_ips) +"| unique visitors: "+to_string( uniqueip_count)+"\n"+temp+"\n"; return temp = company_name + " | number of visitor: " + buf + "| unique visitors: " + buf2 + "\n" + temp + "\n"; } }
the warning because function declared return string
, compiler has determined it's possible may not that. have return
statement returns string in if
statement. when total_ips
0
, won't execute block of code, , you'll never execute return
statement. since don't have else
block, you'll exit function, without returning string required. need change to:
if (total_ips != 0) { ... } else { return ""; }
so return when condition fails.
Comments
Post a Comment