コード例 #1
0
ファイル: shlmch.c プロジェクト: bendisposto/BToolkit
sys_shlfunc()
#define sys_shl sys_shlfunc()
{register int st,i,v ;
  st=cre(1);
  fprintf ( bstdout, "Shell (0 to quit): ");
  read_str(st);
  while( len_str(st)==0 ){
    fprintf ( bstdout, "\n");
    fprintf ( bstdout, "Shell (0 to quit): ");
    read_str(st);
  }
  while( fst_str(st)!=ord('0') ){
    itr_str(st,i,v,cstr_shl[i-1]=chr(v));
    cstr_shl[len_str(st)]='\0';
    fprintf ( bstdout, "\n");
    system(cstr_shl);
    fprintf ( bstdout, "\n");
    fprintf ( bstdout, "Shell (0 to quit): ");
    read_str(st);
    while( len_str(st)==0 ){
      fprintf ( bstdout, "\n");
      fprintf ( bstdout, "Shell (0 to quit): ");
      read_str(st);
    }
  }
}
コード例 #2
0
//-----------------------------------------------------------------------------------------
void no_function_call_copy( string to_str , string from_str )
{
	assert( from_str );
	assert( to_str );
	assert( (   len_str( to_str ) ) >= (  len_str( from_str ) ) );

	while( *from_str != nil )
	{
		*to_str = *from_str;
		double_increment( to_str , from_str );
	}
	*to_str = nil;
}
コード例 #3
0
//---------------------------------------------------------------------------
boolean compare_str_mem( const string first , const string second )
{
	assert( first && second );

	size_t dw_first = ( len_str( first ) );
	size_t dw_second = ( len_str( second ) );
	int dw = 0;

	if( dw_first == dw_second )
	{
		dw = memcmp( (const void*) first , (const void*) second , dw_first );
	}

	return ( dw == 0 ? True : False );
}
コード例 #4
0
ファイル: ft_itoa.c プロジェクト: vcourtin/42.sh
char		*ft_itoa(int n)
{
	char	*str;
	size_t	i;
	size_t	neg;

	neg = is_neg(n);
	i = len_str(n);
	str = ft_strnew(neg + i + 1);
	if (n == -2147483648)
		return (ft_strcpy(str, "-2147483648"));
	if (is_neg(n))
		n = n * -1;
	if (str)
	{
		if (!n)
			str[0] = '0';
		while (n)
		{
			str[--i + neg] = (n % 10) + '0';
			n = n / 10;
		}
		if (neg)
			str[0] = '-';
	}
	return (str);
}
コード例 #5
0
/*driver code*/
void main( )
{  
   char puzzle[MAX_SIZE][SIZE];
     
   printf("\n*********************** part1  & part2 **********\n");    
   int lines=0;
   fill_puzzle_matrix(puzzle,&lines);
   printf("Printing the puzzle ...\n");
   print_puzzle(puzzle,lines);
   printf("\n************************** part3 ********************\n");    
   bool b ;
   b= is_same_word(puzzle,lines,"LOVE",2,1,'a');
   if(b)
   {
	printf("there is LOVE starting on puzzle (2,1) across.. \n");
    }
    else
        printf("LOVE is not found..\n");
    

    printf("\n************************** part4 ********************\n");    
    if(b)
    {
	mark_puzzle(puzzle,lines,2,1,'a',4);
	print_puzzle(puzzle,lines);
    }

    printf("\n************************** part5 ********************\n");    
    char choose='y';
    while(choose == 'y'){
    
    	char wordd[SIZE];
    	int xPoint, yPoint;
    	char dir,space;
        printf("Enter the word:");
        scanf(" %s",wordd);
        printf("Enter the starting point of the word ,and the direction [across:a, down: d]on puzzle matrix:");
    	scanf(" %d %d %c",&xPoint,&yPoint,&dir);
    	
        b= is_same_word(puzzle,lines,wordd,xPoint,yPoint,dir);
	if(b)
	{
                printf("\nThe word is found and replace with '*'character.\n");
		mark_puzzle(puzzle,lines,xPoint,yPoint,dir,len_str(wordd));
	} 
        printf("The word is not found in puzzle.");
        print_puzzle(puzzle,lines);
        printf("\nDo you want to continue ? [yes(y) or no(n)] : ");
	scanf(" %c",&choose) ; 
         
    }

    printf("\n************************** part6_BONUS **************\n");    
    
    char word[SIZE];
    printf("Enter the word:");
    scanf("%s",word);
    int* par;
    is_found(puzzle,lines,word,par);
}
コード例 #6
0
int main(int argc, char** argv){
  char * str;
  char * dest;
  printf("Please enter a string: ");
  scanf("%s\n", str);
  printf("The length of the string is: %d\n", len_str(str));
  cpy(dest, str);
  printf("%s\n", dest);
}
コード例 #7
0
/*ThE function that checks whether the word is in the puzzle or not.The function
takes puzzle matrix m, the size of the matrix n, the string word as input parameters.
The difference of this part from the Part3 is that the function should founds the
location point and direction ,and returns them as an integer array : x, y, d (0 represents
across and 1 represents down) respectively.*/
void is_found( char m[][SIZE],int n, char word[],int* params)
{
  int len=len_str(word);
  bool b=false,flag=false;
  int x,y;
  for(x=0;x<n && b==false;x++)
  {  
	for(y=0;y<=(SIZE-len) && b==false;y++)
        {
		if(DEBUG) printf("\nThe check point %d %d .. ",x,y);        
		b=is_same_word(m,n,word,x,y,'a');
	        if(b)
	      	{ 
			if(DEBUG) printf("\nThe check point(1) %d %d .. ",x,y);        
		 	*params=x;
	       		*(params+1)=y;
	       		*(params+2)=0;
	       	}
	}
  }
  if(b==false )
  {
	for(x=0;x<=(n-len) && b==false;x++)
  	{  
		for(y=0;y<=(SIZE) && b==false;y++)
        	{
			if(DEBUG) printf("\nThe check point %d %d .. ",x,y);        
			b=is_same_word(m,n,word,x,y,'d');
		        if(b)
		      	{ 
				if(DEBUG) printf("\nThe check point(2) %d %d .. ",x,y);        
			 	*params=x;
		       		*(params+1)=y;
		       		*(params+2)=1;
				
		       	}
		}
  	}
  }
  if(b==false)  printf("....!!!!!!!!!!!!!!!!The word is not found.........");
   else 
    {      if(*(params+2)==1)
                printf("\n--------The word is found on %d %d starting point and down direction.. \n",*params,*(params+1));
            else
		printf("\n--------The word is found on %d %d starting point and across direction..\n ",*params,*(params+1));
           
     }   
   
}
コード例 #8
0
//---------------------------------------------------------------------------
void str_reverse( char begin_str[] )
{
	 assert( begin_str );

	 char temp;
	 char* end_str;

	 end_str = begin_str + len_str( begin_str ) - 1;
	 while( end_str > begin_str )
	 {
		 temp = *end_str;
		 *end_str = *begin_str;
		 *begin_str = temp;

		 down_and_up( end_str , begin_str );
	 }
}
コード例 #9
0
/*The function that checks whether the word is in the puzzle or not. The function
takes puzzle matrix m, the size of the matrix n, the string word, the location on x axis,
location on y axis and the direction d ('a' represents across and 'd' represents down) as
input parameters. The function should return a value of type bool.*/
bool is_same_word( char m[][SIZE],int n, char word[],int x,int y,char d)
{
    int count;
    int length= len_str(word);
   	
    
    bool flag=false;		
    
    if(d=='d')
    { 
         if((x+length)>SIZE)
        	return flag;
        		 
         for(count=0;count<length;count++)
         {
            if( m[x+count][y]!=word[count])
                return flag;
		 
         }
         if(count==length)
           { 
                flag=true; 
		return flag;
            }
    }
    else if(d=='a')
    {  
	 if((y+length)>SIZE)
		 return flag;
         for(count=0;count<length;count++)
         {   
	     	if( m[x][count+y]!= word[count])
		    return flag;
   	}
        if(count==length)
         { 
                flag=true;
		return flag;
         }
    }
    else
        {  printf("You enter wrong direction"); return flag;}
    
   
}
コード例 #10
0
ファイル: ft_xitoa.c プロジェクト: chrysa/Al-Cu
char					*ft_xitoa(long unsigned int n, char c)
{
	char				*str;
	size_t				i;

	i = len_str(n);
	str = ft_strnew(i);
	if (str)
	{
		if (!n)
			str[0] = '0';
		while (n)
		{
			str[--i] = hexprint(n, c);
			n = n / 16;
		}
	}
	return (str);
}
コード例 #11
0
//---------------------------------------------------------------------------
//array of booleans corresonding to 256 ascii character set. iterating through
//the string each character is set to True as it occurs. If the ascii 'bit' is
//already set , duplicate characters exist.
boolean is_unique_chars_in_str( char str[] )
{
    boolean b_ret = False;
    string local = str;
    //hash for ascii chars
    boolean char_set[char_set_sz];
    for( int i = 0; i < (int) len_str( local ); i++ )
    {
	    int ascii = str[i];
	    if( char_set[ascii] == True )
	    {
		    b_ret = False;
		    break;
	    }
	    char_set[ascii] = True;
    }

    return ( b_ret );
}
コード例 #12
0
ファイル: ft_slltstr.c プロジェクト: Kraftyy/42
void			ft_slltstr(long long n, char *buf)
{
	int			size;

	if (n == 0)
	{
		buf[0] = '0';
		buf[1] = 0;
		return ;
	}
	size = len_str(n);
	buf[size + 1] = 0;
	if (n < 0)
		buf[0] = '-';
	while (n)
	{
		buf[size] = ABS(n % 10) + '0';
		size--;
		n /= 10;
	}
}
コード例 #13
0
ファイル: cpp_zhtclient.cpp プロジェクト: kwangiit/matrix
int copystring(char *c_str, string str) {

    int i, j;
    int len = str.length();

    for (i = 0; i < 5; i++) {
        c_str[i] = '\0';
    }

    stringstream ss;
    ss << len;
    string len_str(ss.str());

    for (i = 0; i < len_str.length(); i++) {
        c_str[i] = len_str[i];
    }
    i = 5;
    /*for(j = 0 ; j < len; j++) {
     c_str[i++] = str[j];
     }*/
    memcpy(&c_str[i], str.c_str(), str.length() + 1);
    //c_str[i++] = '\0';
    return (i + len);
}
コード例 #14
0
ファイル: sort_data.c プロジェクト: dieuson/42-projects
int				*compare_len(char *flags, t_file *files, int *tab)
{
	if (flags && (ft_strchr(flags, 'l') || ft_strchr(flags, 'g')))
	{
		tab[0] = len_str(files->rights) > tab[0] ?
									len_str(files->rights) : tab[0];
		tab[1] = len_nb(files->link) > tab[1] ?
									len_nb(files->link) : tab[1];
		tab[2] = len_str(files->owner) > tab[2] ?
									len_str(files->owner) : tab[2];
		tab[3] = len_str(files->owner_grp) > tab[3] ?
									len_str(files->owner_grp) : tab[3];
		tab[4] = len_nb(files->size) > tab[4] ?
									len_nb(files->size) : tab[4];
		tab[5] = len_str(files->date[0]) > tab[5] ?
									len_str(files->date[0]) : tab[5];
		tab[6] = len_str(files->date[1]) > tab[6] ?
									len_str(files->date[1]) : tab[6];
		tab[7] = len_str(files->date[2]) > tab[7] ?
									len_str(files->date[2]) : tab[7];
	}
	tab[8] = len_str(files->name) > tab[8] ? len_str(files->name) : tab[8];
	return (tab);
}