我对我创建的一个简单函数有一个奇怪的问题.此函数生成0-14之间的随机数,然后使用随机生成的数字作为大小创建一个数组,并使用char'x'填充它.
我遇到的问题是,当我调用该函数时,它将在x之后随机显示符号或数字.
我最初将数组声明为15号,但认为这是导致此显示问题的剩余插槽.但是,更改功能后它仍然存在.
这是我正在使用的当前功能:
void application()
{
int randSize, i;
srand((unsigned)time(NULL));
randSize = (rand() % 15);
char array[randSize];
char *bar = array;
for(i=0; i< randSize; i++)
array[i] = 'x';
printf("%s | ", bar);
}
Run Code Online (Sandbox Code Playgroud) 我目前正在完成一个类的asp.net项目,并开始注意到一个必要条件之一的主要缺陷.应用程序应该询问五个问题并将答案写入数据库,然后它应该向用户显示调查结果.
这是我到目前为止所尝试的:
public static string GetConnectionString()
{
string connStr = String.Format("server={0}; user id={1}; password={2};" + "database= -table to be accessed-; pooling=false",
"-database server-", "-user-", "-password-");
return connStr;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string sex = gender.Text;
string likes = interests.Text;
string edu = education.Text;
string nation = nationality.Text;
string userage = age.Text;
MySql.Data.MySqlClient.MySqlConnection mycon;
mycon = new MySqlConnection(GetConnectionString());
try
{
MySqlCommand cmd = new MySqlCommand("INSERT INTO survey (gender, age, birthplace, occupation, winner) VALUES ('" …Run Code Online (Sandbox Code Playgroud)