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

📄 smbsstring.c

📁 一个用于银行视频联播网中客户端广告机的网络通信部分
💻 C
字号:
#include "SmBsString.h"  int SubStringV3(const char * OriString,const char * StartToken, const char * EndToken, const int MaxNewStringfLenth,char NewString[]) {      char * BeginIndex;      char * EndIndex;      char * tempIndex;      int TotalLength,NewStringLength,StartTokenLength,EndTokenLength;       int i;            *NewString = '\0';      /*Check total length*/      TotalLength = strlen(OriString );      if ( TotalLength == 0 ) return ERROR_LENGTHISZERO;            /*Check start token length*/      StartTokenLength = strlen(StartToken );      if ( StartTokenLength == 0 ) return ERROR_LENGTHISZERO;            /*Check endtoken length*/      EndTokenLength = strlen(EndToken );      if ( EndTokenLength == 0 ) return ERROR_LENGTHISZERO;                  /*Check exist of the token*/      BeginIndex =   strstr(OriString, StartToken);      if ( BeginIndex == NULL )   return ERROR_LENGTHISZERO;             /*Check exist of the token*/       tempIndex =  (char *)(BeginIndex + StartTokenLength);      EndIndex =   strstr(tempIndex, EndToken);      if ( EndIndex == NULL ) return ERROR_LENGTHISZERO;           /*Check exist of the token*/            /*printf( " BeginIndex = %u\r\n",BeginIndex);            printf( " EndIndex = %u\r\n",EndIndex);                  printf( " TotalLength = %d\r\n",TotalLength);                        printf( " EndIndex - BeginIndex = %u\r\n",EndIndex - BeginIndex);*/     if(! ( BeginIndex < EndIndex && EndIndex - BeginIndex <  TotalLength  ) )return ERROR_LENGTHINVALID;     /*check the maxium of the buffer*/     NewStringLength =   EndIndex -   BeginIndex - StartTokenLength ;      if ( NewStringLength + 1 >   MaxNewStringfLenth ) return  ERROR_EXCESSMAXLENGTH;         /*Copy new string*/     for ( i =  0; i < NewStringLength; i ++)     {          NewString[i] =   *(BeginIndex  + StartTokenLength + i );     }           NewString[i] =   '\0';                                                                                    return 0;              }       void strLeftTrim( char buffer[] ) {                  char * ori, * des;     ori = buffer;     des = buffer;                   /*Find pre blank*/     while ( *ori != '\0' )     {         if ( *ori != ' ')  break;                  ori ++;   }          /*Copy the left chars*/    while ( *ori != '\0' )     {             *des = * ori;         des++;         ori ++;   }   *des = '\0';    }   void strRightTrim( char buffer[] ) {               char * ori, *des;     int length;          ori = buffer;     des = buffer;     /*Move to the finnal */     length = strlen( buffer );     ori = buffer +   length - 1;              while ( ori >= des )     {         if ( *ori != ' ')  break;                  ori --;   }         if ( (int) ori > (int)buffer )     {            *(ori + 1) = '\0';   }   else   {       *buffer = '\0';           }   return; }  void strTrim(char buffer[]) {     char * bori,*eori, *des;     int length,count;          bori = buffer;     while ( *bori != '\0' )     {         if ( *bori != ' ')  break;                  bori ++;     }        /*Move to the finnal */     length = strlen( buffer );     eori = buffer +   length - 1;              while ( eori >= bori )     {         if ( *eori != ' ')  break;                  eori --;     }         count = 0;      while ( eori >= bori )     {         buffer[count++] = *bori;             bori ++;     }   buffer[count] ='\0'; }  void BsItoa(const int value,char Buffer[]){int count ;int i;char temp[20];char zero;int curvalue;curvalue =  value;zero = '0';count = 0;if(value==0){	Buffer[0]='0';       Buffer[1]='\0';}while ( curvalue > 0 ){       i =  curvalue % 10    ;curvalue = ( curvalue - i )/10;temp[count++] = zero + i;    }for ( i = 0; i < count ; i ++){ Buffer[i] = temp[count - i -1];    }   Buffer[count] = '\0';return; }int BsAtoU(char * ValueString){int count ;int length;char zero,nine;char tempchar[128];int rtv;int right ;int i;zero = '0';nine = '9';length = strlen(ValueString);strcpy(tempchar,ValueString);strLeftTrim(tempchar);strRightTrim(tempchar);length = strlen(tempchar);rtv = 0;right = 10;for ( i = 0; i < length ; i ++){  if ( tempchar[i] < zero ||  tempchar[i] > nine ) return -1;   rtv = rtv * right + tempchar[i] - zero;  }  return rtv;}  /*把字串转换成整形*/int Str_to_int(const char * ValueString){int count ;int length;char zero,nine;char tempchar[128];int rtv;int right ;int i;zero = '0';nine = '9';length = strlen(ValueString);strcpy(tempchar,ValueString);strLeftTrim(tempchar);strRightTrim(tempchar);length = strlen(tempchar);rtv = 0;right = 10;for ( i = 0; i < length ; i ++){  if ( tempchar[i] < zero ||  tempchar[i] > nine ) return -1;   rtv = rtv * right + tempchar[i] - zero;  }  return rtv;}int my_strchr(char str[],char str1[],char ch){ int i,count=0,len=0;memset(str1,0,sizeof(str1)); while(*str==(char*)NULL) 	return (-1); while(*str&&*str!=ch) 	{ 	*str1++=*str++;	count++; 	}  *str1='\0';  return count;}int getmark(char buf[],char ch){  int count=0,len=0;  while(*buf==(char*)NULL)  	return;  len=strlen(buf);  while(len>0)  	{	 if(*buf==ch)	 	count++;	  *buf++;	 len--;  	}  return count;}void Copy_String(char buf1[],char buf2[],int len){ strcpy(buf2,(buf1+len+1)); memset(buf1,0,sizeof(buf1)); strcpy(buf1,buf2); memset(buf2,0,sizeof(buf2)); return;}void Read_to_File( char *filename,char buf[],int mode){  FILE *fp=NULL;  if(mode==0){  	if((fp=fopen(filename,"wb+"))==NULL){		perror("file0 open!");  		} }else if(mode==1){       if((fp=fopen(filename,"ab+"))==NULL)	   	perror("file1 open!");  	fprintf(fp,"%s,",buf);  	} else if(mode==2){      if((fp=fopen(filename,"ab+"))==NULL)	  	perror("file2 open!");	 fprintf(fp,"<%s>\r\n",buf); } else if(mode==3){   if((fp=fopen(filename,"wb+"))==NULL)   	 perror("file3 open!");        fprintf(fp,"%s",buf); } else if(mode==4){    if((fp=fopen(filename,"ab+"))==NULL)	perror("file4 open!");    fprintf(fp,"%s\r\n",buf); } else if(mode==5){if((fp=fopen(filename,"ab+"))==NULL)	perror("file5 open!");fprintf(fp,"[%s]",buf); }  fclose(fp);  return ;}void getpath(char buff[],int maxnum,char pathname[]){strTrimlf(buff);pathname[0]='/';pathname[1]=buff[0];pathname[2]=buff[1];pathname[3]=buff[2];pathname[4]=buff[3];pathname[5]='/';pathname[6]=buff[4];pathname[7]=buff[5];pathname[8]='/';pathname[9]='\0';strcat(pathname,buff);if(maxnum<strlen(pathname))	return;return;}#if 1 void strTrimlf(char buffer[]) {     char * bori,*eori, *des;     int length,count;          bori = buffer;     while ( *bori != '\0' )     {         if ( *bori != ' ')  break;                  bori ++;     }        /*Move to the finnal */     length = strlen( buffer );     eori = buffer +   length - 1;              while ( eori >= bori )     {         if ( *eori != ' ')  break;                  eori --;     }         count = 0;      while ( eori >= bori )     {         buffer[count++] = *bori;             bori ++;     }   buffer[count] ='\0'; } #endif    int  FileGetLine(FILE *fp, char *buffer, int maxlen)    {	int  i, j; 	char ch1; 		for(i = 0, j = 0; i < maxlen; j++) 	{ 		if(fread(&ch1, sizeof(char), 1, fp) != 1) 		{ 			if(feof(fp) != 0) 			{ 				if(j == 0) return -1;    				else break; 			} 			if(ferror(fp) != 0) return -2;       			return -2; 		} 		else 		{ 			if(ch1 == '\n' || ch1 == 0x00) break; 			if(ch1 == '\f' || ch1 == 0x1A)       			{ 				buffer[i++] = ch1; 				break; 			} 			if(ch1 != '\r') buffer[i++] = ch1;  		} 	} 	buffer[i] = '\0'; 	return i; }

⌨️ 快捷键说明

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