void parser::skip_whitespace() { int c; while ( (c = fgetchar()) != EOF && isspace(c) ) ; move_back(c); }
int TestMysql() { int res, j; MYSQL mysql; MYSQL_RES *resultset; MYSQL_ROW row; mysql_init(&mysql);// 初始化mysql结构 //连接本机,用户名是root,密码是hope,数据库是hope,端口是3306 if (!mysql_real_connect(&mysql, "127.0.0.1", "root", "123456", "test", 3306, NULL, 0)) { printf("\n数据库连接发生错误 %d!", mysql_errno(&mysql)); } else { printf("\n数据库连接成功!\n"); //插入一条数据到数据库 res = mysql_query(&mysql, "insert into student(name,age,rollno) values('elisa',33,'3')"); if (!res) { printf("插入%lu行数据成功!\n", (unsigned long)mysql_affected_rows(&mysql)); } else printf("插入数据失败!\n"); if (mysql_query(&mysql, "select * from student")) { printf("数据库查询发生错误"); } else { //检索数据 printf("\n查询数据为:\n"); resultset = mysql_store_result(&mysql);// 获得结果集 if (mysql_num_rows(resultset) != NULL) { int numRows = mysql_num_rows(resultset); // 获得结果集中的记录数 int numFields = mysql_num_fields(resultset);// 获得表中字段数 printf("共 %d 行记录,每行 %d 个字段。", numRows, numFields); j = 1; while (row = mysql_fetch_row(resultset)) { int i = 0; printf("\n 第 %d 行:", j); for (i = 0; i < numFields; i++) { fprintf(stdout, " %s", row[i]); // 打印字段值 } j++; } } else { printf("\n无查询结果!"); } mysql_free_result(resultset); // 释放结果集 } } mysql_close(&mysql); // 释放数据库连接 fgetchar(); return 0; }
// Read from current location to the next occurence of specified char. void readToChar (FILE * in, char fchar, BOOL preceedingNewline) { char prevChar = 0; while (TRUE) { int curChar = fgetchar(in); if ((curChar == fchar && (!preceedingNewline || prevChar == '\n')) || curChar == EOF) return; prevChar = curChar; } }
void openQueryFile(AlignmentArgs_t * AAs) { // Open the query file. qFile = openForSeqRead(AAs->qfileName); // Look at the first character to decide if it is a fasta or fastq file. // This also positions the input where readNextQuery expects to be. flockfile(qFile); AAs->fastq = FALSE; if (fgetchar(qFile) == '@') AAs->fastq = TRUE; funlockfile(qFile); }
int testin(int i) { if ( i >= charsread) { if (i!=charsread) { fprintf(stderr,"Symbols not processed\n"); exit(1); } buff[i % QUEUESIZE] = fgetchar(fi); if (buff[i % QUEUESIZE]==-1) buff[i % QUEUESIZE]=0; charsread++; } return buff[i % QUEUESIZE]; }
std::string parser::next_token() { int c; std::string s; skip_whitespace(); while ( (c = fgetchar()) != EOF && !isspace(c) ) s += c; return s; }
main( ) { char ch ; printf ( "\nPress any key to continue" ) ; getch( ) ; /* will not echo the character */ printf ( "\nType any character" ) ; ch = getche( ) ; /* will echo the character typed */ printf ( "\nType any character" ) ; getchar( ) ; /* will echo character, must be followed by enter key */ printf ( "\nContinue Y/N" ) ; fgetchar( ) ; /* will echo character, must be followed by enter key */ }
void main() { char c; // Se ejecuta asi: // Oprimir caracter y <R> // Cuando se quiera finalizar, se orpime CTRL-Z while (!feof(stdin)) { c = fgetchar (); fputchar(c); } }
void db_in(int score) { int res; char* name; MYSQL mysql; mysql_init(&mysql); // 初始化mysql结构 //mysql_real_connect()函数的功能是连接一个MYSql数据库服务器, //MYSQL结构地址是&mysql,host主机名或地址是localhost, //用户名是root,密码是root,数据库是mydb,端口是3306 if (!mysql_real_connect(&mysql, "localhost", "root", "", "snake", 3306, NULL, 0)) { printf("\n数据库连接发生错误!"); } else { printf("\n数据库连接成功!\n"); //插入一条数据到数据库 switch(ms) { case 200:mul=1;break; case 100:mul=2;break; case 50 :mul=4;break; default:break; } ///////////取时间 time ( &rawtime ); timeinfo = localtime ( &rawtime ); name=input_name(); sprintf(sql_insert, "INSERT INTO score(name,score,time) values('%s','%d','%s')",name,mul*score,asctime (timeinfo)); res = mysql_query(&mysql, sql_insert); if(res) { printf("插入数据失败!\n"); }else { printf("成绩输入成功\n"); } } mysql_close(&mysql); // 释放数据库连接 printf("任意键重试!"); fgetchar(); replay(); }
void setUart0Baud(UINT32 baud) { UINT32 baudDiv,baudRemainder; uartReg_t* puartReg; puartReg = (uartReg_t *)0xb0000000; // The UART0 register mapping baudDiv = 48000000/baud; baudRemainder = 48000000%baud; puartReg->baudDiv[0] = baudDiv&0x000000ff; puartReg->baudDiv[1] = (baudDiv>>8)&0x000000ff; puartReg->baudDiv[2] = (baudDiv>>16)&0x000000ff; while(fgetchar()!=0xffff) { } hwWait(1, 3); // units: 10us }
void readNextQuery(AlignmentArgs_t * AAs, QueryState_t * QS) { // Lock the input file. flockfile(qFile); // Continue until we find a valid read or hit end of file. QS->queryLen = 0; while (TRUE) { // First read in the ">" or "@" line for the query ID. int charCount = 0; while (TRUE) { int curChar = fgetchar(qFile); // Check if we are done. if (curChar == '\n' || curChar == EOF) break; // Input the next char into the query ID buf (if it will fit), // Also convert spaces to underscores to aid further pipeline commands. if (charCount < MAX_QUERY_ID_LEN) { QS->queryID[charCount] = (curChar == ' ' ? '_' : curChar); } charCount += 1; } if (charCount > MAX_QUERY_ID_LEN) { fprintf(stderr, "Warning, Query Id length of %d exceeds maximum length %d. Id will be truncated.\n", charCount, MAX_QUERY_ID_LEN); QS->queryIDLen = MAX_QUERY_ID_LEN; } else { QS->queryIDLen = charCount; } // Now read in the query string. int reverseOff = AAs->maxQueryLength; char breakChar = AAs->fastq ? '+' : '>'; int qbaseCount = 0; BOOL Fail = FALSE; while (TRUE) { int curChar = fgetchar(qFile); if (curChar == breakChar || curChar == EOF) break; if (curChar == '\n') continue; // Check to see that we are within bounds of maximum query length. if (qbaseCount >= AAs->maxQueryLength) { fprintf(stderr, "Warning. Query sequence exceeds maximum length of %d. Query will be skipped.\n", AAs->maxQueryLength); // Throw away rest of query. readToChar(qFile, breakChar, FALSE); Fail = TRUE; break; } // process the next char of the query. // We fill both the forward and reverse query buffers as we go along. // In each case, store both the char for the base for output. // And also the 4-bit code for comparison to compressed reference. char forCode = map8to4(curChar); QS->forwardBuf[qbaseCount] = curChar; QS->forwardCodeBuf[qbaseCount] = forCode; reverseOff -= 1; char revCode = complement4to4(forCode); QS->reverseBufBase[reverseOff] = unmap4to8(revCode); QS->reverseCodeBufBase[reverseOff] = revCode; qbaseCount += 1; } // For a fastq file, we need to also find the quality string. int qualCount = 0; if (AAs->fastq) { // The '+' line can contain extra information. // First dump that. readToChar(qFile, '\n', FALSE); // Reading in the quality informtion is harder, as the @ needs to be preceded by a newline. // Given that '@' and newlines can appear in the quality string, // is even that good enough to ensure we are at the start of a new query? char prevChar = 0; while (TRUE) { int curChar = fgetchar(qFile); if ((curChar == '@' && prevChar == '\n') || curChar == EOF) break; prevChar = curChar; if (curChar == '\n') continue; if (qualCount >= AAs->maxQueryLength) { fprintf(stderr, "Warning. Quality score sequence exceeds maximum length of %d. Query will be skipped.\n", AAs->maxQueryLength); // Throw away rest of quality string readToChar(qFile, '@', TRUE); Fail = TRUE; break; } QS->qualBuf[qualCount] = curChar; qualCount += 1; } // Make sure the fastq file is well formed. if (qbaseCount != qualCount) { fprintf(stderr, "Warning. Query sequence (%d) and quality score sequence (%d) have different lengths in fastq file." " Query will be skipped.\n", qbaseCount, qualCount); Fail = TRUE; } } if (qbaseCount > 0 && qbaseCount < AAs->wordLen) { fprintf(stderr, "Query length must be at least wordlen bases long. Query will be skipped.\n"); Fail = TRUE; } // If anything has gone wrong, try again. if (Fail) continue; funlockfile(qFile); // Fill in the QS fields of interest. // Since reverse buf is filled in from back to front, now set the starting ptrs. QS->reverseCodeBuf = &QS->reverseCodeBufBase[reverseOff]; QS->reverseBuf = &QS->reverseBufBase[reverseOff]; QS->queryLen = qbaseCount; // Use the query sequence to generate a random seed for stocastically choosing amonst equal alignments. // By using the query sequence for the seed, the same one is chosen among equals regardless of file context of the query. generateRandomSeed(QS); return; } // This will never be executed, as EOF will result in qbaseCount of zero in while(TRUE) loop. // It is here just to avoid the compiler warning. return; }
int getchar(void) { return fgetchar(DEFAULT_UART); }
void main (int argc, char **argv) { struct stat f_stat; int c, c1, state, i, j, subst, subst1; ushort c2; fprintf(stderr, "rewrite: Utility for dictionary rewriting the standard input to the standard output\n"); if (argc!=4) { printf("Usage:\nrewrite <alphabet> <info_dic> <comp_dic>"); exit(1); } fi = fopen(argv[1],"rb"); memset(codes, 0, 65536*sizeof(int)); for (letter_count=1; (c=fgetchar(fi))>=' '; letter_count++) { if (codes[c] != 0) { printf("Duplicated letter in the alphabet! \n"); exit(1); } codes[c] = letter_count; letters[letter_count]=c; } fclose(fi); stat(argv[2],&f_stat); fi = fopen(argv[2],"rb"); infos = malloc(f_stat.st_size); fread(infos, 1, f_stat.st_size, fi); fclose(fi); stat(argv[3],&f_stat); fi = fopen(argv[3],"rb"); cells = malloc(f_stat.st_size); fread(cells, 1, f_stat.st_size, fi); fclose(fi); fi = stdin; //fopen(argv[4],"rb"); fo = stdout; //fopen(argv[5],"wb"); state = cell_to_int(0); i=0; j=0; subst=-1; subst1=0; ushort newline = '\n'; while (testin(i)!=0) { c=testin(j); c1 = codes[c]; if (c1!=0 && cells[state+c1].tc.c==c1) { state = cell_to_int(state+c1); if (cells[state].tc.c==0) { subst = j; subst1 = cell_to_int(state); } j++; } else { if (subst!=-1) { i=subst+1; j=i; state = cell_to_int(0); fwrite(infos+subst1,sizeof(ushort),wstrlen(infos+subst1),fo); fwrite() subst=-1; } else { c2 = testin(i); fwrite(&c2,sizeof(ushort),1,fo); // write char as is to stream i++; j=i; state = cell_to_int(0); } } } // fclose(fi); // fclose(fo); }
void parser::skip_line() { int c; while ( (c = fgetchar()) != EOF && c != '\n' ) ; }