aa

>cat genRequest.c 
#include <time.h>
#include <ctype.h>
#include <stdio.h>

#define YUID_LEN_DEFAULT 32
typedef int bool;
#define false 0;
#define true 1;

int getRandomChar()
{
        struct timespec time1={0, 0};
        int asCode;

        while(1)
        {
                clock_gettime(CLOCK_REALTIME, &time1);
                //srand((unsigned)(time1.tv_sec + time1.tv_nsec));
                srand((unsigned)( time1.tv_nsec));
                asCode = rand()%128;
                //
                //Only letters, numbers, underscores, and one dot (.) are allowed.
                if (  ('A'<= asCode && asCode <= 'Z') ||
                      ('a' <= asCode &&  asCode<= 'z' ) ||
                      ('0' <= asCode && asCode <= '9') ||
                      asCode == '_' ||
                      asCode == '.' ) break;
                //printf("%c:%d\n", asCode, asCode);
        }
        return asCode;
}
/**uage:
 * if 1 argument is appended, the argument is the yuid length when it is not greater than 32, else 32 is its length
 *
 */
int main(int argc, char * argv[])
{
        int headerLen;

        if ( argc == 2 )
        {
                int arg = atoi( argv[1] );
		if ( arg < 32 && arg >= 8)
		   headerLen= arg;
		else
		   headerLen = YUID_LEN_DEFAULT;
		
        }
        else
        {
                struct timespec time1={0, 0};
                clock_gettime(CLOCK_REALTIME, &time1);
                srand((unsigned)(time1.tv_nsec));
                //Your username must be between 8 and 32 characters long
                // rand()%(Y-X+1)+X;
                headerLen = rand()%(YUID_LEN_DEFAULT - 7) + 8;
        }

        int asCode=0;
        char header32B[33] = {0};
        char tail2B[3]={0};
        int tailLen = 2;
        int i, j;
	bool SingleDot=false;
	bool SingleUnderScore=false;
        
        for ( i=0;  i < headerLen; ++i)
        {
		while( 1 )
		{
		   char tmp = (char)getRandomChar();
		   if ( i == 0 ) {
                       if( !isalpha(tmp) )  continue;
			header32B[0] = tmp; break ;
		   }
		   if ( tmp == '.' ) {
			if ( SingleDot || header32B[i-1] == '_' ) continue;
			
			header32B[i] = tmp;
		        SingleDot = true;
			break;
		   }
    		   if ( tmp == '_') {
			if( SingleUnderScore || header32B[i-1] == '.')  continue;

			header32B[i] = tmp;
			SingleUnderScore = true;
			break;
		   }
                   header32B[i] = tmp;
		   break;
		}
	}
/*
           header32B[i]=(char)getRandomChar();
	   if ( i == 0 ) 
	   {
		        //yuid must begin with a letter
              while( !isalpha(header32B[0]) )
              {
               header32B[0]=(char)getRandomChar();
              }
              continue;
	   }
           if( header32B[i] == '.' && !isSingleDot )
	   {
	   }
        }
*/	
	//for gen a tail
        for ( j=0; j < tailLen ; ++j )
           tail2B[j] = (char)getRandomChar();
        //tail character indicating the regester time should be alphanumeric
        while (!isalnum(tail2B[0]))
        {
           tail2B[0] = (char)getRandomChar();
        }
        while (!isalnum(tail2B[1]))
        {
           tail2B[1] = (char)getRandomChar();
        }

        printf("%s#%s\n", header32B, tail2B);
        return 0;
}


typedef enum __bool { false = 0, true = 1, } bool;
c90是没有bool的,因此支持c90的dev-c++当然也没有。想在c90里用bool,可以自行用宏进行定义。 
c99支持bool,用支持c99的编译器例如gcc就可以的。


C语言里面没有bool(布尔)类型
C++里面才引入bool类型
C语言里面用数值0表示假,非0整数表示真(一般是1)

c中bool类型的定义 及其他

standard c 是没有bool类型的。一般来说c可以用int来判断对错,返回0是否,其他是对。
 

确实需要时自己可以定义一个:用枚举类型

typedef enum {FALSE, TRUE
} bool;

c里边也没有DWORD类型,如果需要用unsigned long int 来定义
 

typedef unsigned long int  DWORD;

一些微软c++的定义如何转到standard c 和 c++可以参考微软MSDN

http://msdn.microsoft.com/en-us/library/cc230309%28PROT.10%29.aspx
 

2.2.1 BOOL

This section contains simple data types that are defined by either a C/C++ typedef or #define statement. The data types in this section are essentially aliases for C/C++ primitive data types.

A BOOL is a 32-bit field that is set to 1 to indicate TRUE, or 0 to indicate FALSE.

This type is declared as follows:

typedef int BOOL, *PBOOL, *LPBOOL;

A BOOLEAN is an 8-bit field that is set to 1 to indicate TRUE, or 0 to indicate FALSE.

This type is declared as follows:

typedef BYTE BOOLEAN, *PBOOLEAN;

A BSTR is a pointer to a null-terminated character string in which the string length is stored with the string. Because the length is stored with the string, BSTR variables can contain embedded null characters. For example:

[4 bytes (length prefix)], 
wchar_t[length], [\0]

This type is declared as follows:

typedef WCHAR* BSTR; 


          
          

A BYTE is an 8-bit unsigned value that corresponds to a single octet in a network protocol.

This type is declared as follows:

typedef unsigned char BYTE, *PBYTE, *LPBYTE; 

A CHAR is an 8-bit block of data that typically contains an ANSI character, as specified in [ISO/IEC-8859-1]. For information on the char keyword, see [C706] section 4.2.9.3.

This type is declared as follows:

typedef char CHAR, *PCHAR; 

A DOUBLE is an 8-byte, double-precision, floating-point number that represents a double-precision, 64-bit [IEEE754] value with the approximate range: +/–5.0 x 10-324 through +/–1.7 x 10308.

The DOUBLE type can also represent not a number (NAN); positive and negative infinity; or positive and negative 0.

This type is declared as follows:

typedef double DOUBLE; 


                 
                 

A DWORD is a 32-bit unsigned integer (range: 0 through 4294967295 decimal). Because a DWORD is unsigned, its first bit (Most Significant Bit (MSB)) is not reserved for signing.

This type is declared as follows:

typedef unsigned long DWORD, *PDWORD, *LPDWORD; 

A DWORD_PTR is an unsigned long type used for pointer precision. It is used when casting a pointer to an unsigned long type to perform pointer arithmetic. DWORD_PTR is also commonly used for general 32-bit parameters that have been extended to 64 bits in 64-bit Windows. For more information, see ULONG_PTR.

This type is declared as follows:

typedef ULONG_PTR DWORD_PTR;

A DWORD32 is a 32-bit unsigned integer.

This type is declared as follows:

typedef unsigned int DWORD32; 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值