⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.c

📁 用于汇编领域的,运用于OS的MAIN函数.基于硬件基础的源代码
💻 C
字号:
// string utility routinesint findloc(char *buf, char c){// return the first appearing location of c in buf// return -1 if no c in buf   int i;   for(i=0;;i++){      if (buf[i]==c) return i;	  if (buf[i]==0) return -1; // end of string   }}void substr(char *buf, char *dest, int beg, int end){// copy buf[beg] to buf[end] into dest. make it a string   int i,j;   for(i=0,j=beg;j<=end;i++,j++)      dest[i]=buf[j];   dest[i]=0;}void write_substr(char *buf, char *dest, int beg, int end){// copy buf into dest[beg]..dest[end].    int i,j;   for(i=0,j=beg;j<=end;i++,j++)      dest[j]=buf[i];}void copystr(char *buf, char *dest){   int i;   for(i=0;;i++){	  dest[i]=buf[i];      if (buf[i]==0) return;   }}void strcpy(char *dest, char *buf){   copystr(buf, dest); // for compatibility}void strncpy(char *dest, char *buf, int len){   int i;   for(i=0;i<len;i++){	  dest[i]=buf[i];   }}int strlen(char *buf){   int i;   for(i=0;;i++)      if (buf[i]==0) return i;}int strcmp(char *s1, char *s2){// return 0 if same; otherwise return -1   int i,n1,n2;   n1=strlen(s1); n2=strlen(s2);   if (n1!=n2) return -1;   for(i=0;i<n1;i++)      if (s1[i]!=s2[i]) return -1;   return 0;}int strncmp(char *s1, char *s2, int len){// return 0 if same; otherwise return -1   int i;   for(i=0;i<len;i++)      if (s1[i]!=s2[i]) return -1;   return 0;}int get_next_tok(char *buf, char *dest, char c){// get substr (delimiter c) in buf to dest// if there is no delimiter in buf, everything is considered// as a substr, so put but into dest in this case, and return// 1 to indicate we didn't find the delimiter   int x;   x=findloc(buf,c);  // the next appearance of c in buf   if (x==-1){ // token is the whole string in buf      copystr(buf, dest);	  return 1; // dest is the leaf of the path   }   else if (x==0) // token is buf[0]      substr(buf, dest, 0, 0);         else //buf[0] to buf[x-1] is the token      substr(buf, dest, 0, x-1);   // we found delimiter   return 0; // normal case}     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -