1. 随机数:
#include <stdio.h>
#include<time.h>
int main(int argc,char *argv[]){
srand((unsigned)time( NULL ));
int k = rand()%26;
return 0;
}
如果没有没有srand更新随机种子,每次的执行总是一样的,现在去当前时间之后,每次的执行就不一样了。
2.分离字符串:
#include <string.h>
#include <stdio.h>
main()
{
char s[]="Golden Global View";
/*
*注意:如果使用char *s ="Golden Global View"; 执行的时候会出现段错误
* 此时s[3]='d';也出错,因为 后面的是字符串常量,s是字符指针变量。原程序中
*中s是字符数组
char *p = (char*) malloc(64);
strcpy(p, "this is a split program");
p[2] = 'd';
此时可以改变
*/
char *d=" ";
char *p;
p=strtok(s,d);
while(p)
{
printf("%s/n",p);
p=strtok(NULL,s);
}
return 0;
}
#include <stdio.h>
#include<time.h>
int main(int argc,char *argv[]){
srand((unsigned)time( NULL ));
int k = rand()%26;
return 0;
}
如果没有没有srand更新随机种子,每次的执行总是一样的,现在去当前时间之后,每次的执行就不一样了。
2.分离字符串:
#include <string.h>
#include <stdio.h>
main()
{
char s[]="Golden Global View";
/*
*注意:如果使用char *s ="Golden Global View"; 执行的时候会出现段错误
* 此时s[3]='d';也出错,因为 后面的是字符串常量,s是字符指针变量。原程序中
*中s是字符数组
char *p = (char*) malloc(64);
strcpy(p, "this is a split program");
p[2] = 'd';
此时可以改变
*/
char *d=" ";
char *p;
p=strtok(s,d);
while(p)
{
printf("%s/n",p);
p=strtok(NULL,s);
}
return 0;
}