int str_del_vowels(char *s){ int counter = 0; int i; int j=0; char copy[10] = ""; printf ("String vorher: %s\n", s); _strcpy(copy,s); printf ("String copy: %s\n", copy); strdel(s); printf ("String geleert: %s\n", s); for (i=0; *(copy+i) != '\0'; i++){ if (isVokal3(*(copy+i))){ counter++; } else{ *(s+j) = *(copy+i); j++; } } printf ("String nachher: %s\n", s); return counter; }
void main() { char string[50]; int position; int length; printf("\nPlease input original string:"); gets(string); printf("\nPlease input delete position:"); scanf("%d",&position); printf("\nPlease input delete length:"); scanf("%d",&length); strdel(string,position,length); printf("\nThe final string:%s",string); getch(); }
int main() { int start, length; char str[] = "Korea University Data Structure"; char *ret_str; printf("문자열 시작 번호, 길이 : "); scanf_s("%d %d", &start, &length); getchar(); ret_str = strdel(str, start, length); printf("%s", ret_str); puts(""); free(ret_str); return 0; }
int main() { void strdel(char *, char *); char cont; char str[50],sstr[10]; int pos; do { fflush(stdin); printf("Enter any string: "); gets(str); printf("Enter any substring: "); gets(sstr); strdel(str, sstr); fflush(stdin); printf("Do you want to continue (y/n)\n"); scanf("%c",&cont); }while( (cont=='Y') || (cont=='y')); }
/* laden von EPHEM VERSION 4.0 Bahnelementdateien */ short elemente_laden( const char datei_name[], ELEMENT& e ) { FILE *f; int dummy; char string[100],a_string[20]; f=fopen(datei_name,"rt"); if (f==NULL) { fprintf(stderr,"Kann Datei %s nicht oeffnen!\n",datei_name); return 0; } fgets(string,100,f); if (strcmp("EPHEM4\n",string)!=0) // keine EPHEM 4.0 Bahnelementdatei { fclose(f); fprintf(stderr,"Die Datei %s ist keine EPHEM 4.x Bahnelementedatei.\n",datei_name); return 0; } fgets(string,100,f); sscanf(string,"%d",&dummy); e.komet=AUS_EIN(dummy % 2); fgets(string,100,f); strcut(string); string[strlen(string)-1]=0; /* '\n' rauswerfen */ strcut(string); strcpy(e.name,string); fgets(string,100,f); sscanf(string,"%s",a_string); strdel(a_string,string); if (strcmp("des_datums",string)==0) { e.a_jd=0.0; e.a_mo=des_datums; } else if (strcmp("j2000",string)==0) { e.a_jd=J2000; e.a_mo=j2000; } else if (strcmp("b1950",string)==0) { e.a_jd=B1950; e.a_mo=b1950; } else { sscanf(string,"%lg",&e.a_jd); e.a_mo=anderes; } fgets(string,100,f); sscanf(string,"%lg",&e.e); fgets(string,100,f); sscanf(string,"%lg",&e.q); fgets(string,100,f); sscanf(string,"%lg",&e.M); fgets(string,100,f); sscanf(string,"%lg",&e.t); fgets(string,100,f); sscanf(string,"%lg",&e.om); fgets(string,100,f); sscanf(string,"%lg",&e.kl); fgets(string,100,f); sscanf(string,"%lg",&e.i); fgets(string,100,f); sscanf(string,"%lg",&e.mag0); fgets(string,100,f); sscanf(string,"%lg",&e.mag1); if (e.e<1.0) /* Elliptische Bahn */ { e.a=e.q/(1.0-e.e); e.n=M_2PI/sqrt(e.a*e.a*e.a*4.0*PI*PI/KGAUSS2); } else if (e.e>1.0) /* Hyperbolische Bahn */ { e.a=e.q/(1.0-e.e); } if (e.M==0.0) e.t0=e.t; e.M *= DEG2RAD; e.om *= DEG2RAD; e.kl *= DEG2RAD; e.i *= DEG2RAD; e.pi=mod(e.om+e.kl,M_2PI); fclose(f); return 1; }
int IntStateQuery() { /* qstat -f Job Id: 11.cream-12.pd.infn.it Job_Name = cream_579184706 job_state = R ctime = Wed Apr 23 11:39:55 2008 exec_host = cream-wn-029.pn.pd.infn.it/0 */ /* Filled entries: batch_id wn_addr status udate Filled by submit script: blah_id Unfilled entries: exitreason */ FILE *fp; char *line=NULL; char **token; int maxtok_t=0; job_registry_entry en; int ret; char *timestamp; time_t tmstampepoch; char *batch_str=NULL; char *wn_str=NULL; char *twn_str=NULL; char *status_str=NULL; char *ex_str=NULL; int ex_code=0; char *cp=NULL; char *command_string=NULL; job_registry_entry *ren=NULL; int first=TRUE; time_t now; char *string_now=NULL; command_string=make_message("%s%s/qstat -f",batch_command,pbs_binpath); fp = popen(command_string,"r"); en.status=UNDEFINED; JOB_REGISTRY_ASSIGN_ENTRY(en.wn_addr,"\0"); JOB_REGISTRY_ASSIGN_ENTRY(en.exitreason,"\0"); JOB_REGISTRY_ASSIGN_ENTRY(en.updater_info,"\0"); en.exitcode=-1; bupdater_free_active_jobs(&bact); if(fp!=NULL){ while(!feof(fp) && (line=get_line(fp))){ if(line && strlen(line)==0){ free(line); continue; } if ((cp = strrchr (line, '\n')) != NULL){ *cp = '\0'; } do_log(debuglogfile, debug, 3, "%s: line in IntStateQuery is:%s\n",argv0,line); now=time(0); string_now=make_message("%d",now); if(line && strstr(line,"Job Id: ")){ if(!first && en.status!=UNDEFINED && ren && ren->status!=REMOVED && ren->status!=COMPLETED){ if ((ret=job_registry_update_recn_select(rha, &en, ren->recnum, JOB_REGISTRY_UPDATE_WN_ADDR| JOB_REGISTRY_UPDATE_STATUS| JOB_REGISTRY_UPDATE_UDATE| JOB_REGISTRY_UPDATE_UPDATER_INFO| JOB_REGISTRY_UPDATE_EXITCODE| JOB_REGISTRY_UPDATE_EXITREASON)) < 0){ if(ret != JOB_REGISTRY_NOT_FOUND){ fprintf(stderr,"Update of record returns %d: ",ret); perror(""); } } else { if(ret==JOB_REGISTRY_SUCCESS){ if (en.status == REMOVED || en.status == COMPLETED) { do_log(debuglogfile, debug, 2, "%s: registry update in IntStateQuery for: jobid=%s wn=%s status=%d exitcode=%d\n",argv0,en.batch_id,en.wn_addr,en.status,en.exitcode); job_registry_unlink_proxy(rha, &en); }else{ do_log(debuglogfile, debug, 2, "%s: registry update in IntStateQuery for: jobid=%s wn=%s status=%d\n",argv0,en.batch_id,en.wn_addr,en.status); } } if (remupd_conf != NULL){ if (ret=job_registry_send_update(remupd_head_send,&en,NULL,NULL)<=0){ do_log(debuglogfile, debug, 2, "%s: Error creating endpoint in IntStateQuery\n",argv0); } } } en.status = UNDEFINED; JOB_REGISTRY_ASSIGN_ENTRY(en.wn_addr,"\0"); JOB_REGISTRY_ASSIGN_ENTRY(en.exitreason,"\0"); JOB_REGISTRY_ASSIGN_ENTRY(en.updater_info,"\0"); en.exitcode=-1; } maxtok_t = strtoken(line, ':', &token); batch_str=strdel(token[1]," "); JOB_REGISTRY_ASSIGN_ENTRY(en.batch_id,batch_str); JOB_REGISTRY_ASSIGN_ENTRY(en.updater_info,string_now); en.exitcode=-1; bupdater_push_active_job(&bact, en.batch_id); free(batch_str); freetoken(&token,maxtok_t); if(!first) free(ren); if ((ren=job_registry_get(rha, en.batch_id)) == NULL){ fprintf(stderr,"Get of record returns error for %s ",en.batch_id); perror(""); } first=FALSE; }else if(line && strstr(line,"job_state = ")){ maxtok_t = strtoken(line, '=', &token); status_str=strdel(token[1]," "); if(status_str && strcmp(status_str,"Q")==0){ en.status=IDLE; en.exitcode=-1; JOB_REGISTRY_ASSIGN_ENTRY(en.wn_addr,"\0"); }else if(status_str && strcmp(status_str,"W")==0){ en.status=IDLE; en.exitcode=-1; }else if(status_str && strcmp(status_str,"R")==0){ en.status=RUNNING; en.exitcode=-1; }else if(status_str && strcmp(status_str,"C")==0){ en.status=COMPLETED; JOB_REGISTRY_ASSIGN_ENTRY(en.exitreason,"\0"); }else if(status_str && strcmp(status_str,"H")==0){ en.status=HELD; en.exitcode=-1; JOB_REGISTRY_ASSIGN_ENTRY(en.wn_addr,"\0"); } free(status_str); freetoken(&token,maxtok_t); }else if(line && strstr(line,"unable to run job")){ en.status=IDLE; en.exitcode=-1; }else if(line && strstr(line,"exit_status = ")){ maxtok_t = strtoken(line, '=', &token); ex_str=strdel(token[1]," "); ex_code=atoi(ex_str); if(ex_code==0){ en.exitcode=0; }else if(ex_code==271){ en.status=REMOVED; en.exitcode=-999; }else{ en.exitcode=ex_code; } free(ex_str); freetoken(&token,maxtok_t); }else if(line && strstr(line,"exec_host = ")){ maxtok_t = strtoken(line, '=', &token); twn_str=strdup(token[1]); if(twn_str == NULL){ sysfatal("strdup failed for twn_str in IntStateQuery: %r"); } freetoken(&token,maxtok_t); maxtok_t = strtoken(twn_str, '/', &token); wn_str=strdel(token[0]," "); JOB_REGISTRY_ASSIGN_ENTRY(en.wn_addr,wn_str); free(twn_str); free(wn_str); freetoken(&token,maxtok_t); }else if(line && strstr(line,"mtime = ")){ maxtok_t = strtoken(line, ' ', &token); timestamp=make_message("%s %s %s %s %s",token[2],token[3],token[4],token[5],token[6]); tmstampepoch=str2epoch(timestamp,"L"); free(timestamp); en.udate=tmstampepoch; freetoken(&token,maxtok_t); } free(line); free(string_now); } pclose(fp); } if(en.status!=UNDEFINED && ren && ren->status!=REMOVED && ren->status!=COMPLETED){ if ((ret=job_registry_update_recn_select(rha, &en, ren->recnum, JOB_REGISTRY_UPDATE_WN_ADDR| JOB_REGISTRY_UPDATE_STATUS| JOB_REGISTRY_UPDATE_UDATE| JOB_REGISTRY_UPDATE_UPDATER_INFO| JOB_REGISTRY_UPDATE_EXITCODE| JOB_REGISTRY_UPDATE_EXITREASON)) < 0){ if(ret != JOB_REGISTRY_NOT_FOUND){ fprintf(stderr,"Update of record returns %d: ",ret); perror(""); } } else { if(ret==JOB_REGISTRY_SUCCESS){ if (en.status == REMOVED || en.status == COMPLETED) { do_log(debuglogfile, debug, 2, "%s: registry update in IntStateQuery for: jobid=%s wn=%s status=%d exitcode=%d\n",argv0,en.batch_id,en.wn_addr,en.status,en.exitcode); job_registry_unlink_proxy(rha, &en); }else{ do_log(debuglogfile, debug, 2, "%s: registry update in IntStateQuery for: jobid=%s wn=%s status=%d\n",argv0,en.batch_id,en.wn_addr,en.status); } } if (remupd_conf != NULL){ if (ret=job_registry_send_update(remupd_head_send,&en,NULL,NULL)<=0){ do_log(debuglogfile, debug, 2, "%s: Error creating endpoint in IntStateQuery\n",argv0); } } } } free(ren); free(command_string); return 0; }
static int ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const TCHAR *tszBaseUrl, SERVLIST& hashes, OBJLIST<FILEINFO> *UpdateFiles) { // skip updater's own folder if (!_tcsicmp(tszFolder, tszRoot)) return 0; // skip profile folder TCHAR tszProfilePath[MAX_PATH]; CallService(MS_DB_GETPROFILEPATHT, SIZEOF(tszProfilePath), (LPARAM)tszProfilePath); if (!_tcsicmp(tszFolder, tszProfilePath)) return 0; TCHAR tszBuf[MAX_PATH]; mir_sntprintf(tszBuf, SIZEOF(tszBuf), _T("%s\\*"), tszFolder); WIN32_FIND_DATA ffd; HANDLE hFind = FindFirstFile(tszBuf, &ffd); if (hFind == INVALID_HANDLE_VALUE) return 0; Netlib_LogfT(hNetlibUser,_T("Scanning folder %s"), tszFolder); int count = 0; do { if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Scan recursively all subfolders if (_tcscmp(ffd.cFileName, _T(".")) && _tcscmp(ffd.cFileName, _T(".."))) { mir_sntprintf(tszBuf, SIZEOF(tszBuf), _T("%s\\%s"), tszFolder, ffd.cFileName); count += ScanFolder(tszBuf, cbBaseLen, level + 1, tszBaseUrl, hashes, UpdateFiles); } } else if (isValidExtension(ffd.cFileName)) { // calculate the current file's relative name and store it into tszNewName TCHAR tszNewName[MAX_PATH]; if (!CheckFileRename(ffd.cFileName, tszNewName)) { if (level == 0) _tcsncpy(tszNewName, ffd.cFileName, MAX_PATH); else mir_sntprintf(tszNewName, SIZEOF(tszNewName), _T("%s\\%s"), tszFolder + cbBaseLen, ffd.cFileName); } TCHAR *ptszUrl; int MyCRC = 0; mir_sntprintf(tszBuf, SIZEOF(tszBuf), _T("%s\\%s"), tszFolder, ffd.cFileName); bool bDeleteOnly = (tszNewName[0] == 0); // this file is not marked for deletion if (!bDeleteOnly) { TCHAR *pName = tszNewName; ServListEntry *item = hashes.find((ServListEntry*)&pName); // Not in list? Check for trailing 'W' or 'w' if (item == NULL) { TCHAR *p = _tcsrchr(tszNewName, '.'); if (p[-1] != 'w' && p[-1] != 'W') continue; // remove trailing w or W and try again int iPos = int(p - tszNewName) - 1; strdel(p - 1, 1); if ((item = hashes.find((ServListEntry*)&pName)) == NULL) continue; strdel(tszNewName + iPos, 1); } ptszUrl = item->m_name; // No need to hash a file if we are forcing a redownload anyway if (!opts.bForceRedownload) { // try to hash the file char szMyHash[33]; __try { CalculateModuleHash(tszBuf, szMyHash); // hashes are the same, skipping if (strcmp(szMyHash, item->m_szHash) == 0) continue; } __except (EXCEPTION_EXECUTE_HANDLER) { // smth went wrong, reload a file from scratch } } MyCRC = item->m_crc; }
char * strdel_wrapper(char *hey, char *needle) { return strdel(needle, hey); }
int OptH(char *Opt) { int optLen = 2; boolean State; optCount++; switch (Opt[1]) { case 'b': fSetBorder = TRUE; strdel(Opt, 0, 2); Border.W = decVal(Opt); if (Opt[0] != ',') Stop(2, Opt); strdel(Opt, 0, 1); Border.H = decVal(Opt); optLen = 0; break; case 'f': fFontSet = TRUE; fResizeWindowToMax = TRUE; strdel(Opt, 0, 2); if (isdigit(Opt[0])) { Font.H = decVal(Opt); if (Opt[0] != ',') Stop(2, Opt); strdel(Opt, 0, 1); Font.W = decVal(Opt); } else { int fw,fh; if (GetConsoleFontSize(&fh, &fw)) { Font.H = fh; Font.W = fw; } } optLen = 0; break; case 'o': optLen += OptState(Opt[3], &State) + 1; switch (Opt[2]) { case 'a': ANSI = State; break; case 'd': fDelay = State; break; case 'r': fResizeWindowToMax = State; break; case 'f': if (State) { fFlashWindow = TRUE; fSetFlash = TRUE; } else { fFlashWindow = FALSE; fSetFlash = TRUE; } break; case 'b': if (State) { sd.FgBg = SSF_FGBG_BACK; fForegroundConsole = FALSE; } else { sd.FgBg = SSF_FGBG_FORE; fForegroundConsole = TRUE; } break; case 'c': if (State) sd.PgmControl &= ~SSF_CONTROL_NOAUTOCLOSE; else sd.PgmControl |= SSF_CONTROL_NOAUTOCLOSE; break; case 'v': if (State) { sd.PgmControl &= ~SSF_CONTROL_INVISIBLE; fHideConsole = FALSE; fShowConsole = TRUE; } else { sd.PgmControl |= SSF_CONTROL_INVISIBLE; fHideConsole = TRUE; fShowConsole = FALSE; } break; case 'x': if (State) { sd.PgmControl |= SSF_CONTROL_MAXIMIZE; sd.PgmControl &= ~SSF_CONTROL_MINIMIZE; fAutoSize = FALSE; fMaximizeConsole = TRUE; fRestoreConsole = FALSE; } else { sd.PgmControl &= ~SSF_CONTROL_MAXIMIZE; fMaximizeConsole = FALSE; fRestoreConsole = TRUE; } break; case 'm': if (State) { sd.PgmControl |= SSF_CONTROL_MINIMIZE; sd.PgmControl &= ~SSF_CONTROL_MAXIMIZE; fMinimizeConsole = TRUE; fRestoreConsole = FALSE; } else { sd.PgmControl &= ~SSF_CONTROL_MINIMIZE; fMinimizeConsole = FALSE; fRestoreConsole = TRUE; } break; case 'n': fNewSession = State; break; case 's': fAutoSize = State; break; default: Stop(2, Opt); } break; case 'p': strdel(Opt, 0, 2); if (isdigit(Opt[0])) { ConsolePos.X = decVal(Opt); fExplicitPos = TRUE; } else if (Opt[0] != ',') GetPixelConsoleSize(&ConsolePos.X, &ConsolePos.Y, &ConsolePos.W, &ConsolePos.H); if (Opt[0] == ',') { strdel(Opt, 0, 1); if (isdigit(Opt[0])) { ConsolePos.Y = decVal(Opt); fExplicitPos = TRUE; } if (Opt[0] == ',') { strdel(Opt, 0, 1); if (isdigit(Opt[0])) { ConsolePos.W = decVal(Opt); fExplicitSize = TRUE; } if (Opt[0] == ',') { strdel(Opt, 0, 1); if (isdigit(Opt[0])) { ConsolePos.H = decVal(Opt); fExplicitSize = TRUE; } } } } optLen = 0; break; case 's': fConsoleSize = TRUE; fResizeWindowToMax = TRUE; strdel(Opt, 0, 2); Console.W = decVal(Opt); if (Opt[0] != ',') Stop(2, Opt); strdel(Opt, 0, 1); Console.H = decVal(Opt); optLen = 0; break; case 't': { int i = 3; int l = strlen(Opt); if (Opt[2] != '"') Stop(2, Opt); while (i < l && Opt[i] != '"') i++; if (Opt[i] != '"') Stop(2, Opt); progtitle = malloc(i - 2); strncpy(progtitle, &Opt[3], i - 3); progtitle[i - 2] = 0; optLen = i + 1; break; } case 'q': fQueryCommand = TRUE; break; case 'w': switch (Opt[2]) { case 'a': sd.SessionType = SSF_TYPE_DEFAULT; break; case 'd': sd.SessionType = SSF_TYPE_WINDOWEDVDM; break; case 'o': sd.SessionType = SSF_TYPE_WINDOWABLEVIO; break; default: Stop(2, Opt); } optLen++; break; case '?': case 'h': Stop(1, NULL); default: Stop(2, Opt); } if ((Opt[optLen] != 0) && (Opt[optLen] != SPACE) && (Opt[optLen] != TAB)) Stop(2, Opt); return optLen; }
void scanForCrossRefs( char *line, int& offset, TCrossRefNode *&xRefs ) { int i; char begXRef = '{'; char endXRef = '}'; char aliasCh = ':'; char *begPtr, *endPtr, *aliasPtr, *tempPtr; int begPos, endPos, aliasPos; char xRef[75]; i = 0; do { if ((begPtr = strchr(line+i,begXRef)) == 0) i = 0; else { begPos = (int)(begPtr - (line+i)); i += begPos + 1; if (line[i + 1] == begXRef) { strdel(line, i, 1); ++i; } else { if ((endPtr = strchr(line+i,endXRef)) == 0) { error("Unterminated topic reference."); ++i; } else { endPos = (int)(endPtr - (line + i)); aliasPtr = strchr(line+i, aliasCh); if ((aliasPtr == 0) || (aliasPtr > endPtr)) { tempPtr = line + i; strncpy(xRef, tempPtr, endPos); xRef[endPos] = 0; addXRef(xRef, (offset + ofs + i), endPos, xRefs); } else { aliasPos = (int)(aliasPtr - (line + i)); tempPtr = line ; tempPtr += aliasPos+i+1; strncpy(xRef, tempPtr, (endPos - aliasPos -1)); xRef[endPos - aliasPos -1] = 0; addXRef(xRef, (offset + ofs + i), (aliasPos), xRefs); strdel(line, (i + aliasPos), (endPos - aliasPos)); endPtr = aliasPtr; endPos = aliasPos; } replaceSpacesWithFF(line, i, endPos -1); strdel(line, i + endPos, 1); strdel(line, i-1, 1); i += (endPos - 2); } } } } while (i != 0); }