学点 C 语言(41): 函数 - 关于 main 函数(2)
printf("---n");
while (--argc) {
printf("%sn", argv[argc]);
}
getchar();
return 0;
}
4. 假如需要其他类型的参数:
main 的参数都是字符串的(或者说是字符指针的), 要使用其他类型的参数, 譬如 int、double 等, 只能转换.
#include
#include
int main(int argc, char* argv[])
{
int I;
long L;
double D;
I = atoi(argv[1]); /* 假定至少指定了一个参数 */
L = atol(argv[1]);
D = atof(argv[1]);
printf("%d, %ld, %gn", I, L, D);
getchar();
return 0;
}
5. C++Builder 2009 中的 main 函数:
//标准的 main 函数:
int main(int argc, char* argv[])
{
return 0;
}
//C++Builder 2009 中的 main 函数:
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
/*
_tmain 是个 define, 在 tchar.h 中这样定义: #define _tmain main
程序在预处理阶段将会把它替换为: main
_TCHAR 是重命名的 char 类型, 在 tchar.h 中这样定义: typedef char _TCHAR;
看来要想按照 C++Builder 2009 给的默认代码使用, 是离不开 tchar.h 的.
C++Builder 2009 为什么要这样? 肯定有理由, 可我不知道.
*/





