int main() { char chars[100]="qweeeeeeeeeeeeerrrrrrtewqerqwraegdbrx"; bool bresult = true; char cduplicated; printf("enter something\n"); scanf("%s",&chars); LARGE_INTEGER t1, t2, ts; QueryPerformanceFrequency(&ts); QueryPerformanceCounter(&t1); for(int i=0 ; i<strlen(chars) ; i++) { cduplicated = chars[i]; //check whether there's duplicated char in the rest of the string for(int j=i+1 ; j<strlen(chars)-1 ; j++) { if(chars[j]==chars[i]) { removechar(&chars[j]); i--; } } } printf("Result:%s\n", chars); QueryPerformanceCounter(&t2); printf("Lasting Time: %lf\n",(t2.QuadPart-t1.QuadPart)/(double)(ts.QuadPart)); system("PAUSE"); return 0; }
int main() { int i=0; char str[200],rm[10]; printf("Enter the String $ to stop\n"); for(str[i]=getchar();str[i]!='$';str[++i]=getchar()); str[i]='\0'; printf("Enter character to remove\n"); scanf("%s",rm); printf("%s",removechar(str,rm)); getch(); }
/*Add access to library functions like sin, exp and pow. See <math.h> in */ void deterfunc(char s[]) { if (strcmp(s, "sin") == 0) { push(sin(pop())); } else if (strcmp(s, "exp") == 0) { push(exp(pop())); } else if (strcmp(s, "pow") == 0) { int t = pop(); push(pow(pop(), t)); } else if (strcmp(s, "swap") == 0) { swap(); } else if (strcmp(s, "duplicate") == 0) { duplicate(); } else if (strcmp(s, "peek") == 0) { printf("\t%.8g\n\n", peek()); } else if (strcmp(s, "clear") == 0) { clear(); } else if (s[0] == '=') { // Assign the last number on the stack to the variable. removechar(s, 0); setvar(s, peek()); } else // Must be a variable then. push((double)getvar(s)); }
std::string processHost() { Json::Value root; // cpu std::string ret = exec_stuff ((const char *)"top -bn2 | grep \"Cpu(s)\" | sed \"s/.*, *\\([0-9.]*\\)%* id.*/\\1/\" | awk '{print $1\"%\"}'", '%'); std::vector<std::string> x = split(ret, ','); for (unsigned i=0; i < x.size(); i++) { std::string name = "cpu_idle_perc_iteration"; std::ostringstream oss; oss << i; name += oss.str(); root[name] = atoi(x[i].c_str()); } // mem ret = exec_stuff ((const char *)"top -bn1 | grep \"KiB Mem\" | sed \"s/.*, *\\([0-9.]*\\)* used.*/\\1/\" | awk '{print $1}'", '\0'); root["mem_used_kib"] = atoi(ret.c_str()); ret = exec_stuff ((const char *)"top -bn1 | grep \"KiB Mem\" | sed \"s/.*, *\\([0-9.]*\\)* free.*/\\1/\" | awk '{print $1}'", '\0'); root["mem_free_kib"] = atoi(ret.c_str()); // disk usage ret = exec_stuff ((const char *)"df | awk '{ print $5,$6}' | grep -vi \"mounted\"", '\n'); x = split(ret, ','); for (unsigned i=0; i < x.size(); i++) { std::string name = "disk_used_perc_"; std::vector<std::string> xx = split(x[i], '%'); name += trim(xx[1]); root[name] = atoi(xx[0].c_str()); } // new iostat // ./iostat -x | awk /./ std::string iostat_cmd = get_custom_iostatpath(); if (iostat_cmd.size() > 0) { iostat_cmd += " -x | awk /./"; ret = exec_stuff (iostat_cmd.c_str(), '\n', 0); x = split(ret, '|'); for (unsigned i=0; i < x.size(); i++) { if (x[i].size() > 0) { std::vector<std::string> xx = split(x[i], ':'); if (xx.size() == 2) { std::string v1 = xx[0]; std::string v2 = xx[1]; v1=trim(v1); std::string name = removechar(v1, '"'); replace(v2, ",", "."); root[name] = atof(trim(v2).c_str()); } } } } else { syslog(LOG_ERR, "Error getting iostat info"); } // hostname char hostname[1024]; if (gethostname(hostname, 1024) == 0) { root["hostname"] = hostname; } std::ostringstream oss; oss << root; return oss.str(); }