int main(int argc, char * * argv) { printf("Welcome to PA02.\n" "\n" "You are encouraged to edit this file in order to test\n" "the behavior of the functions you write in answer02.c\n" "\n" "This file will not be marked, and should not be\n" "submitted.\n" "\n" "Don't forget to post questions on blackboard, and ask\n" "the TAs and your classmates for help.\n" "\n"); const char * s1 = "Hello World!"; const char * s2 = ""; const char * s3 = "foo"; // -- my_strlen, should be: 12, 0, and 3 printf("my_strlen(\"%s\") = %d\n", s1, (int) my_strlen(s1)); printf("my_strlen(\"%s\") = %d\n", s2, (int) my_strlen(s2)); printf("my_strlen(\"%s\") = %d\n", s3, (int) my_strlen(s3)); // -- my_countchar, should be: 3, 0, and 2 printf("my_countchar(\"%s\", 'l') = %d\n", s1, (int) my_countchar(s1, 'l')); printf("my_countchar(\"%s\", 'o') = %d\n", s2, (int) my_countchar(s2, 'o')); printf("my_countchar(\"%s\", 'o') = %d\n", s3, (int) my_countchar(s3, 'o')); // -- my_strchr, should be: "llo World!", "(null)", and "" printf("my_strchr(\"%s\", 'l') = %s\n", s1, my_strchr(s1, 'l')); printf("my_strchr(\"%s\", 'o') = %s\n", s2, my_strchr(s2, 'o')); printf("my_strchr(\"%s\", '\\0') = %s\n", s3, my_strchr(s3, '\0')); // -- my_strstr, should be: "World!", "Hello World!", "(null)" printf("my_strstr(\"%s\", \"World\") = %s\n", s1, my_strstr(s1, "World")); printf("my_strstr(\"%s\", \"\") = %s\n", s1, my_strstr(s1, "")); printf("my_strstr(\"%s\", \"hello\") = %s\n", s1, my_strstr(s1, "hello")); // -- my_strcpy. For this function you need a buffer where you // copy the string to. char buffer[BUFFER_LEN]; my_strcpy(buffer, s1); printf("my_strcpy(buffer, \"%s\"), buffer = \"%s\"\n", s1, buffer); my_strcpy(buffer, s2); printf("my_strcpy(buffer, \"%s\"), buffer = \"%s\"\n", s2, buffer); my_strcpy(buffer, s3); printf("my_strcpy(buffer, \"%s\"), buffer = \"%s\"\n", s3, buffer); // -- my_strcat. You will have to do this yourself... just // look at my_strcpy for an example, and go from there. // -- my_isspace. You will have to do this for yourself. // -- my_atoi. You will have to do this for yourself. return EXIT_SUCCESS; }
void checkpoint(t_lidar *lidar, int *i) { init_data(lidar); if (my_strstr(lidar->info_lidar, "Track Cleared") != NULL || my_strstr(lidar->forward, "Track Cleared") != NULL || my_strstr(lidar->backwards, "Track Cleared") != NULL || my_strstr(lidar->wheel, "Track Cleared") != NULL) *i = 1; turn(lidar); }
static bool_t cipstart_deal(void) { recv.offset = 0; if (my_strstr((const char*)recv.buf, (const char*)"CLOSED") != NULL) return FALSE; else if (my_strstr((const char*)recv.buf, (const char*)"ALREADY CONNECT") != NULL) return TRUE; else if (my_strstr((const char*)recv.buf, (const char*)"CONNECT") != NULL) return TRUE; else return FALSE; }
int main() { char str[]="abcdefg"; char sub[]="cde"; printf("%d",my_strstr(str,sub)); return 0; }
int main(int ac, char ** av) { #ifndef TES int a = 5; int n = SQUARE(13); printf("%d\n",n); PSQR(4.25,"%g"); #endif //printf("%d",sizeof(u)); /*int i; BSTree test; int arr[] = {20,15,18,32,5,91,-4,76,33,41,34,21,90}; int size = sizeof(arr) / sizeof(arr[0]); init_tree(&test); for(i = 0;i < size;i++) insert_tree(&test,arr[i]); level_traversal_tree(&test);*/ /*set_buffer(); printf("%d plus %d equals %d\n",a,b,a + b); longjmp(jbuf,1); printf("After longjmp\n");*/ char * arr = my_strstr("abcde","bc"); puts(arr); printf("\n"); return 0; }
void file_dfs(char *arg, t_vector *stack, t_vector *dirs, char *name) { struct stat dd; struct dirent *dp; char *path_name; char *dirname; DIR *dir; dirname = (vector_size(dirs) ? dir_from_vector(dirs) : my_strdup("./")); if ((dir = opendir(dirname))) { while ((dp = readdir(dir)) != NULL) { path_name = complete_path(dirname, dp->d_name); if (lstat(path_name, &dd) == -1) my_fprintf(2, "globbing: can't stat %s\n", path_name); if ((name[0] != '.') && (dp->d_name[0] == '.')); else if ((S_ISDIR(dd.st_mode) || (!my_strstr(arg, "/"))) && (match(dp->d_name, name))) matching_file(arg, stack, dirs, dp); xsfree(path_name); } closedir(dir); } xsfree(dirname); }
void exec_cmd_low_level(t_param *param, t_cmd *cmd) { char *path; char *cmd_path; if (my_strstr(cmd->arg[0], "/") == 0) { while ((path = get_next_path(param->env))) { cmd_path = xsmalloc(my_strlen(path) + my_strlen(cmd->arg[0]) + 2); my_strcpy(cmd_path, path); my_strcat(cmd_path, "/"); my_strcat(cmd_path, cmd->arg[0]); xsfree(path); if (access(cmd_path, F_OK) != -1) execve(cmd_path, (cmd->arg), environ); xsfree(cmd_path); } my_fprintf(2, "%s: command not found\n", cmd->arg[0]); } else { execve(cmd->arg[0], cmd->arg, environ); my_fprintf(2, "%s: can't exec\n", cmd->arg[0]); } free_all(param); exit(1); }
static bool_t cipstatus(void) { recv.offset = 0; if (my_strstr((const char*)recv.buf, (const char*)"CONNECT OK") != NULL) return TRUE; else return FALSE; }
static bool_t ate0_deal(void) { recv.offset = 0; if (my_strstr((const char*)recv.buf, (const char*)ATOK) != NULL) return TRUE; else return FALSE; }
char * strstr (const char *s1, const char *s2) { if (inside_main) abort (); return my_strstr (s1, s2); }
int main() { char A[100], B[20]; scanf("%s %s", A, B); printf("%d\n", my_strstr(A, B)); return 0; }
void matching_file(char *arg, t_vector *stack, t_vector *dirs, struct dirent *dp) { char *file_name; if (my_strstr(arg, "/")) { vector_push(dirs, (void *)complete_path(dp->d_name, "/")); add_matching_files(my_strstr(arg, "/") + 1, stack, dirs); xsfree(vector_pop(dirs)); } else { file_name = dir_from_vector(dirs); vector_push(stack, (void *)complete_path(file_name, dp->d_name)); xsfree(file_name); } }
void main(int argc,char **argv) { char s1[] = "hello how are you?"; char s2[] = "how "; printf("%s\n",s1); char *pointer = my_strstr(s1, s2); if(pointer) printf("%s\n", pointer); }
/* 查找子串,若未找到则返回-1 */ int MyString::indexOf(const char *search) const { char *pos = my_strstr(_str, search); if (pos == 0) { return -1; } else { return (int)(pos - _str); } }
static int buf_search(BUF *buf, const char *str) { char *ret; ret = my_strstr(buf->data, str); if (!ret) return -1; return ret - buf->data; }
int add_matching_files(char *arg, t_vector *stack, t_vector *dirs) { char *name; if ((my_strlen(arg) == 0) && !vector_push(stack, (void *)dir_from_vector(dirs))) return (0); if (trim_left_path(arg, stack, dirs, "/")) return (0); if (trim_left_path(arg, stack, dirs, "./")) return (0); if (trim_left_path(arg, stack, dirs, "../")) return (0); name = my_strdup(arg); if (my_strstr(arg, "/")) *(my_strstr(name, "/")) = 0; file_dfs(arg, stack, dirs, name); xsfree(name); return (0); }
char *shorten_pwd(t_mysh *mysh, char *env_pwd) { char *home; home = key_to_value(mysh->my_env, "HOME"); if (home != NULL && my_strstr(env_pwd, home) != NULL) { return (my_str_replace(home, "~", env_pwd, -1)); } return (my_strdup(env_pwd)); }
char explorer_on_enter_file(char *file_name, char *path, t_explorer *explorer) { if (!my_strstr(file_name, explorer->extension)) my_putstr("Ce fichier n'est pas au bon format !\n"); else { explorer->img = path; return (1); } return (0); }
void uart_deal_task(void *p) { while(TRUE) { if( xSemaphoreTake( guart_Semaphore, portMAX_DELAY ) == pdTRUE ) { vTaskDelay(300 / portTICK_RATE_MS); esn_msg_t esn_msg; esn_msg.event = GPRS_EVENT; if(gprs_info.gprs_state == WORK_ON) { if (my_strstr((const char*)recv.buf, (const char*)GPRS_CIPSEND[1]) != NULL) { memset(recv.buf, 0 , SIZE); e_state = E_SEND; xQueueSend(gprs_queue, &esn_msg, portMAX_DELAY); } else if (my_strstr((const char*)recv.buf, (const char*)"SEND OK\r\n") != NULL) { memset(recv.buf, 0 , SIZE); e_state = E_SEND_OK; xQueueSend(gprs_queue, &esn_msg, portMAX_DELAY); } else if (my_strstr((const char*)recv.buf, (const char*)"ERROR") != NULL) { uart_deal_close(); } else if (my_strstr((const char*)recv.buf, (const char*)"SEND FAIL") != NULL) { uart_deal_close(); } else if(my_strstr((const char*)recv.buf, (const char*)"CLOSED") != NULL) { uart_deal_close(); } } } } }
/* 高效率的字符串分割实现 */ std::vector<MyString>& my_split(const char *str, const char *delim) { auto *ret = new std::vector<MyString>; const char *posBegin = str, *posEnd = nullptr; while ((posEnd = my_strstr(posBegin, delim)) != nullptr) { ret->push_back(MyString(posBegin, (int)(posEnd - posBegin))); posBegin = posEnd + 1; } ret->push_back(MyString(posBegin)); return *ret; }
int is_correct_command_config(char *line, int line_nbr) { int i; i = 0; while (line && line[i]) { if (line[i] == ' ' || line[i] == '\t') i++; if (my_strstr(&line[i], "setenv") != NULL || my_strstr(&line[i], "alias") != NULL) return (1); else { if (line_nbr != -1) my_printf("%s: the line %d is not correct.\n", CONFIG_FILE_NAME, line_nbr); return (1); } i++; } return (0); }
int is_dble_redir_left(t_vars *v) { int i; i = 0; while (v->argv[i]) { if ((find_char(v->argv[i], '<') != -1 && my_strstr(v->argv[i], "<<") != -1) || my_strcmp(v->argv[i], "<<") == 0) return (DB_RE_LEF); i += 1; } return (SMTH_ELSE); }
int is_dble_redir_right(t_vars *v) { int i; i = 0; while (v->argv[i]) { if ((find_char(v->argv[i], '>') != -1 && my_strstr(v->argv[i], ">>") != -1) || my_strcmp(v->argv[i], ">>") == 0) return (DB_RE_RIG); i += 1; } return (SMTH_ELSE); }
/* 分割字符串 */ std::vector<MyString>& MyString::split(const char *delim) const { MyString clone = _str; auto *ret = new std::vector<MyString>; char *posBegin = _str, *posEnd; while ((posEnd = my_strstr(posBegin, delim)) != 0) { ret->push_back(clone._substring((int)(posBegin - _str), (int)(posEnd - posBegin))); posBegin = posEnd + 1; } ret->push_back(clone.substring((int)(posBegin - _str), -1)); return *ret; }
char *get_goto_dir(t_mysh *mysh, char **args) { char *home_val; if ((args[1] == NULL || args[1][0] == 0) && !env_key_exist_v(mysh->my_env, "HOME")) return (NULL); if (!env_key_exist(mysh->my_env, "HOME")) return (my_strdup(args[1])); home_val = key_to_value(mysh->my_env, "HOME"); if (args[1] != NULL && my_strstr(args[1], "~") != NULL) return (my_str_replace("~", home_val, args[1], -1)); if (args[1] == NULL || args[1][0] == 0) return (home_val); return (my_strdup(args[1])); }
int main(int argc, const char *argv[]) { char *str1 = "this cocool is cool play"; char *str2 = "cool"; char *p1; char *p2; p1 = strstr(str1, str2); printf("%s\n", p1); printf("===========\n"); p2 = my_strstr(str1, str2); printf("%s\n", p2); return 0; }
char *my_strstr(char *str, char *to_find) { int i; if (str[0]) { i = 0; while (to_find[i]) { if (to_find[i] != str[i]) return (my_strstr(str + 1, to_find)); i = i + 1; } return (str); } else return (0); }
int main(int argc, char* argv[]) { char s1[] = "zxcvbn"; char s2[] = "rb"; char *x; x = my_strstr(s1, s2); if(x == NULL) { printf("not found\n"); } else { printf("%s\n",x); } return 0; }
char *alias_var_replacing(t_mysh *mysh, char *alias) { char *var; char *key; char *first_value; char *tmp; tmp = my_strdup(alias); if (tmp == NULL) return (alias); var = my_strstr(tmp, "$"); if (var == NULL) return (alias); first_value = get_first_value_arg(var); key = key_to_value(mysh->my_env, first_value + 1); if (env_key_exist(mysh->my_env, first_value + 1)) alias = my_str_replace(var, key, alias, -1); free(first_value); free(key); return (alias); }
int main() { char inputstr[99] = { 0, }; char substr[99] = { 0, }; int index = 0; char a = '김'; printf("%c", a); printf("최대 99개 입력 <inputstr> : "); scanf("%s", inputstr); printf("찾는 문자열 <substr> : "); scanf("\n%s", substr); my_strstr(inputstr, substr, &index); if (index == -1) printf("%s의 위치 : 찾고자 하는 문자열 '%s'가 존재하지 않습니다. ", substr, substr); else printf("%s의 위치 : %d", substr, index + 1); }