No.01
我只学过VB
我想知道在VB
For 变量 = 数字 To 数字
…
Next
或
Do
…
Loop //这个不管用
这句话在VC里怎么实现
如果看不懂这句话的人
就是循环指定次数的代码
-
近期文章
近期评论
- coolker 发表在《打造最快的Hash表》
- struggle 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- diys 发表在《C语言编程宝典(王大刚) 1.1 C 语言的产生与发展》
文章归档
- 2022 年十月
- 2014 年一月
- 2013 年十二月
- 2012 年十一月
- 2012 年七月
- 2012 年六月
- 2012 年五月
- 2012 年四月
- 2012 年三月
- 2012 年二月
- 2011 年十二月
- 2011 年十月
- 2011 年九月
- 2011 年八月
- 2011 年七月
- 2011 年六月
- 2011 年五月
- 2011 年四月
- 2011 年三月
- 2011 年二月
- 2011 年一月
- 2010 年十二月
- 2010 年十一月
- 2010 年十月
- 2010 年九月
- 2010 年八月
- 2010 年七月
- 2010 年六月
- 2010 年五月
- 2010 年四月
- 2010 年三月
- 2010 年二月
- 2010 年一月
- 2009 年十二月
- 2009 年十一月
- 2009 年十月
- 2009 年九月
- 2009 年八月
- 2009 年七月
- 2009 年六月
- 2009 年五月
- 2009 年四月
- 2009 年三月
- 2009 年二月
- 2009 年一月
- 2008 年十二月
- 2008 年十一月
- 2008 年十月
- 2008 年九月
- 2008 年八月
- 2008 年七月
- 2008 年六月
- 2008 年五月
- 2008 年四月
- 2008 年三月
- 2008 年二月
- 2008 年一月
- 2007 年十二月
- 2007 年十一月
- 2007 年十月
- 2007 年九月
- 2007 年八月
- 2007 年七月
- 2007 年六月
- 2007 年三月
- 2007 年二月
- 2007 年一月
- 2006 年十二月
- 2006 年十一月
- 2006 年十月
- 2006 年九月
- 2006 年八月
- 2006 年七月
- 2006 年六月
- 2006 年五月
- 2006 年四月
- 2006 年三月
- 2006 年二月
- 2006 年一月
- 2005 年十二月
- 2005 年十一月
分类目录
功能
No.02
弹出一个对话框
VB里MsgBox(内容,方式,标题)
No.03
q34608 38810.8699305556
初始化随机数生成器
VB里Randomize
产生随机数
VB里Rnd()
No.04
q34608 38810.8728819444
打开一个文件
读一个文件
写一个文件
No.05
定义一个变量
VB里Dim 变量 As 形势
No.01
For 变量 = 数字1 To 数字2
…
Next
循环次数为(数字2 – 数字1 + 1),数字2参与循环,改为C/C++如下
int iLoop;
for ( iLoop = 数字1; iLoop <= 数字2; iLoop++ ) { // 循环条件同VB中的,这里演示的是递增.
…;
}
Do
…
Loop //这个不管用
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
根据意思可以转换为
while ( condition ) {
…;
}
或
do {
…;
} while ( condition );
No.02
int MessageBox( HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
MessageBox( NULL, 内容, 标题, 方式 );//第一个参数为当前窗口的指针,可以为NULL
No.03
#include <stdlib.h>
void srand( unsigned int seed ); // 初始化种子
int rand( void ); // 得到随机数
No.04
这块内容比较多,具体看书,这里给个例子:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _BUF_LEN 16384
void usage( char *proname );
int crlftolf( char *s_buf, char *d_buf, int isrclen );
int main( int argc, char *argv[] )
{
FILE *s_fp;
FILE *d_fp;
char s_buf[ _BUF_LEN ];
char d_buf[ _BUF_LEN ];
int tread = 0;
int twrite = 0;
int numread = 0;
int numwrite = 0;
int numtowrite = 0;
if ( 3 != argc ) {
usage( argv[ 0 ] );
exit( 1 );
}
if ( 0 == strcmp( argv[ 1 ], argv[ 2 ] ) ) {
usage( argv[ 0 ] );
exit( 1 );
}
if ( (FILE *)NULL == ( s_fp = fopen( argv[ 1 ], “rb” ) ) ) {
printf( “Open File %s Error\n”, argv[ 1 ] );
exit( 1 );
}
if ( (FILE *)NULL == ( d_fp = fopen( argv[ 2 ], “wb” ) ) ) {
fclose( s_fp );
printf( “Open File %s Error\n”, argv[ 2] );
exit ( 1 );
}
while( !feof( s_fp ) ) {
numread = fread( s_buf, 1, _BUF_LEN, s_fp );
if ( ferror( s_fp ) ) {
printf( “Read error %s”, argv[ 1 ] );
break;
}
numtowrite = crlftolf( s_buf, d_buf, numread );
numwrite = fwrite( d_buf, 1, numtowrite, d_fp );
tread += numread;
twrite += numwrite;
}
printf( “PROGRAM: read %d bytes, write %d bytes\n”, tread, twrite );
fclose( d_fp );
fclose( s_fp );
return 0;
}
void usage( char *proname )
{
printf( “%s by XStar[xstar.wxb]\n\n”, proname );
printf( “convert 0D0A to 0A\n” );
printf( “usage:\n\t%s s_file d_file\n”, proname );
}
int crlftolf( char *s_buf, char *d_buf, int isrclen )
{
int icnt = 0;
int iloop = 0;
for ( iloop = 0; iloop < isrclen; iloop++ ) {
if ( 0x0D == *(s_buf + iloop) ) { /* delete 0x0D */
continue;
}
*(d_buf + icnt ) = *(s_buf + iloop);
icnt++;
}
return icnt;
}
No.05
这块内容看VC/VB混合编程,几点注意的是VB中尽量不要用Integer和Boolen类型,这两种类型都用Long类型代替,因为VB中Integer类型是16位的,Boolen类型的true和false与VC中的定义不同.
其他的主要是传内存时最好在VB中分配好空间,然后传地址给VC;
定义的例子
Dim lLoop As long
long lLoop;