sprintf , srand
#include <stdio.h>
#include <string.h>
void main()
{
char buf[100];
char name[100];
int i;
for(i=1 ; i<10 ; i++){
strcpy_s(name, "jo" );
sprintf_s(buf,"%d",i); // buf라는 배열에 i값을 ( 문자열형태로 )넣기 , 실제 출력기능이 아님
strcat_s(name,buf);
printf("%s\n",name);
}
}
#include <stdio.h>
#include <string.h>
void main()
{
char buf[100];
char name[100];
int x;
int i;
for(i=1 ; i<10 ; i++){
x = rand()%100; // random number producing , 난수를 2자리 수로 제한( %100 )
strcpy_s(name, "jo" );
sprintf_s(buf,"%d",x);
strcat_s(name,buf);
printf("%s\n",name);
}
}
#include <stdio.h>
#include <string.h>
#include <time.h> // srand함수를 쓰기 위한 헤더파일
void main()
{
char buf[100];
char name[100];
int x;
int i;
srand((unsigned)time(NULL)); // seeding random number
// The random numbers produced are same, so using srand makes the numbers different at each time.
for(i=1 ; i<10 ; i++){
x = rand()%100; // pseudo random number producing
strcpy_s(name, "jo" );
sprintf_s(buf,"%d",x);
strcat_s(name,buf);
printf("%s\n",name);
}
}