int main(void) { int choice; if(file2mem() == FAIL){ printf("信息文件读取出错\n"); return 1; } while(1){ print_choice(); scanf("%d",&choice); switch(choice){ case ADD: add_student();break; case DEL: delete_student();break; case CGE: change_student();break; case F_NAME: find_name();break; case F_NUM: find_number();break; case SORT: sort_score();break; case PRT: print_student();break; case EXIT: return 0; } getchar(); printf("请按任意继续\n"); getchar(); } }
int main(int argc, char **argv) { file2mem(); struct problem **problems = &problem_first; printf("%s", (*problems)->data->problem); while(*problems) { struct data *data = (*problems)->data; //printf("%s\n", data->problem); struct num *num = data->num; while(num) { printf("|%d|-", num->num); num = num->next; } problems = &(*problems)->next; } return 0; }
void *do_work(void *argv) { char header[4096] = ""; char rsp[4096] = ""; char path[1024] = "."; int connfd = -1; int rv = -1; char *pos, *p; int size = 0; connfd = (intptr_t)argv; rv = recv(connfd, header, sizeof(header) - 1, MSG_PEEK); if (rv == -1) { printf("recv peek fail %s\n", strerror(errno)); goto done; } printf("===%s===\n", header); if (strncmp("GET", header, 3)) { printf("header is %s\n", header); goto done; } pos = strstr(header, "\r\n\r\n"); if (pos == NULL) { printf("not found \\r\\n\\r\\n \n"); goto done; } /*read */ rv = recv(connfd, header, pos - header + 4, 0); sscanf(header, "GET %[^ ]", path + 1); printf("path(%s)\n", path); rv = file2mem(path, &p, &size); if (rv == -1) { printf("file2mem fail\n"); return 0; } if (strncmp(path + strlen(path) - 4, ".mp3", 4) == 0) { printf("mp3 type"); rv = snprintf(rsp, sizeof(rsp) - 1, RSP_BODY_MEDIA, size); } else { rv = snprintf(rsp, sizeof(rsp) - 1, RSP_BODY_FILE, size); } /*write rsp*/ write(connfd, rsp, rv); /*write body*/ write(connfd, p, size); done: close(connfd); return 0; }
int main(int argc, char **argv) { int r; char *p = NULL; int n = 0; int size; int lastSectFlag = 1; HANDLE_MRCPINTF asr_handle; HANDLE_MRCPINTF service_handle; char text[MAX_RECOG_TEXT_LEN] = ""; r = usc_mrcp_asr_init(&asr_handle, "asrConfig/ctx.ini", 1); if(r < 0){ printf("\n usc_mrcp_asr_init failed\n"); } printf("\n usc_mrcp_asr_init OK!\n"); r = usc_mrcp_service_init( &service_handle, asr_handle, NULL); if(r < 0){ printf("\n usc_mrcp_service_init failed\n"); } printf("\r\nusc_mrcp_service_init OK!\n"); usc_mrcp_service_set_option(service_handle, USC_SAMPLE_RATE, "8k"); r = usc_mrcp_service_start(service_handle); if(r < 0){ printf("\n usc_mrcp_service_start failed\n"); } printf("\n usc_mrcp_service_start OK!\n"); file2mem("test.wav", &p, &n); usc_mrcp_service_set_option(service_handle, USC_SAMPLE_RATE, "8k"); printf("usc_mrcp_service_set_option ok\n"); usc_mrcp_service_recognize( service_handle, p + 44, n - 44, lastSectFlag); printf("usc_mrcp_service_recognize ok\n"); size = usc_mrcp_service_get_recg_result(service_handle , text, MAX_RECOG_TEXT_LEN-1); printf("usc_mrcp_service_get_recg_result ok\n"); printf(":::::: asr result: %s\n",text); usc_mrcp_service_release(service_handle); printf("usc_mrcp_service_release OK!\n"); usc_mrcp_asr_destroy(asr_handle); printf("usc_mrcp_asr_destroy OK!\n"); return 0; }
int file2argv(const char *name, char ***vec) { int j; int length; int newlines; /* number of newlines found */ int lines; /* number of newlines found */ char **p, *blob; char *s, *d; *vec = 0; /* in case we find an error */ if ((blob = file2mem(name)) == 0) return (-1); for (s = blob, lines = 0; *s; ++s) if (*s == '\n') lines++; length = (int) (s - blob); newlines = lines; if (length > 0 && blob[length - 1] != '\n') lines++; /* * Reallocate space for the file counting the nulls inserted * after each newline. */ if ((blob = doalloc(blob, AMOUNT(length + lines + 1))) == 0) return (-1); /* * Allocate space for the vector pointing to the strings */ *vec = p = vecalloc((size_t) (lines + 1) * sizeof(char *)); /* * Recopy the blob onto itself, putting a null after each newline. */ for (j = newlines, s = blob + length, d = s + newlines; d != s;) { if (*s == '\n') { p[j--] = d + 1; *d-- = EOS; } *d-- = *s--; } p[lines] = 0; /* always supply a null-pointer */ p[0] = blob; return (lines); }