我的程序中有strcmp的问题.
我试图按照它们的长度比较两个字符串,所以我使用strcmp(),但是当我在if语句中比较它们时它不能正常工作.
strcmp不比较字符串的长度吗?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char a[30],b[30],c[30];
strcpy(a,"computer");
strcpy(c,"science");
strcpy(b,a);
puts(a);
puts(c);
puts(b);
if(strcmp(a,b)==0)
printf("a=b\n");
if(strcmp(a,c)<0)
printf("a<c\n");
if(strcmp(a,c)>0)
printf("a>c");
strcat(a,c);
puts(a);
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个任务是使用PLINQ并行化迭代.为此,我有一个基于for-cycle的功能:
public void PointGenerator(int n, Random rnd)
{
for (int i = 1; i <= n; i++)
{
x = rnd.NextDouble();
y = rnd.NextDouble(); //
if (((x - 0.5) * (x - 0.5) + (y - 0.5) * (y - 0.5)) < 0.25)
{
N_0++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能用PLINQ呢?
我试图插入我的C#应用程序中的SQL数据库.
我已经阅读了一些文档,并提出了我认为可行的方法.实际上,当用户输入他们的数据并按下提交按钮时,应用会暂停一段时间,然后给我一个"SqlException",并提到一些无法连接的事情.
我不确定我是否正确使用了连接字符串,所以我正在寻求帮助.
这些是我用来构建查询并建立连接的方法:
private void btn_Submit_Click(object sender, EventArgs e)
{
if (isValidData())
{
//MessageBox.Show("Valid", "All Entries Were Valid!");
//CONVERT FORM VALUES AND STORE IN VARIABLES TO SEND TO MYSQL QUERY
DateTime saleTime = saleDatePicker.Value;
Decimal price = Convert.ToDecimal(txt_Price.Text);
string customerName = txt_CustomerName.Text;
string customerPhone = txt_CustomerPhone.Text;
string description = rTxt_Description.Text;
//Build Query string
string query = "INSERT into SALES VALUES ('" + saleTime + "','" +
price + "','" + customerName + "','" + customerPhone + "','" +
description …Run Code Online (Sandbox Code Playgroud) 我是初学者并且有一个任务,我必须编写NIM游戏.我从15个"令牌"开始,每回合最多可以删除三个"隐藏".到目前为止,我通过执行以下操作隐藏了这些令牌.
private void button1_Click(object sender, EventArgs e)
{
button1.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
button2.Visible = false;
}
Run Code Online (Sandbox Code Playgroud)
我只是复制并粘贴了多次,并更改了按钮编号,以便我的按钮在点击时关闭.这可能是显而易见的,但有没有更有效的方法来做到这一点,而不是有15个按钮关闭方法?
我的数据访问层从DBConfig静态类获取具有静态字段(ServerName,DBName,UserName,Password)的连接数据.
现在我需要与不同的DBConfig建立两个连接,我试图制作另一个dll项目,然后添加我的dal来建立另一个组件的另一个连接,当我试图添加结果的DLL作为主项目的参考,并尝试更改DBConfig数据然后更改主项目的dbconfig类字段
主要项目
static void Main()
{
DBConfig.DbName = "InvDB";
DBConfig.Password = "3343402";
DBConfig.ServerName ="ziad-pc";
DBConfig.UserName = "admin";
DBConfig.Lang = "AR";
GLINVSERVICES.ServiceConfig.Init("ZIAD-PC", "GLTest", "admin", "3343402");
}
Run Code Online (Sandbox Code Playgroud)
另一个DLL项目
namespace GLINVSERVICES
{
public static class ServiceConfig
{
public static void Init(string ServerName, string DBName, string UserName, string Password)
{
DBConfig.Datatype = EgxDataType.Mssql;
DBConfig.DbName = DBName;
DBConfig.Lang = "AR";
DBConfig.ServerName = ServerName;
DBConfig.UserName = UserName;
DBConfig.Password = Password;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我需要分离DBConfig静态类,以便我可以建立不同的连接
我是编码的新手,我正在用C#创建一个Windows窗体应用程序.我在确定如何跟踪数量correct和incorrect响应方面遇到了困难.单击按钮时,如果响应是correct标签说明正确.我想要一个不同的标签来计算它说正确和不正确的次数.这是我的想法,但没有奏效.
int add = 0;
add = int.Parse(correct.Text);
if (label1.Text == "Correct")
{
correct.Text = add++;
}
else
incorrect.text = add++;
Run Code Online (Sandbox Code Playgroud)
correct并且incorrect是我的标签的名称.
这是我的按钮点击事件,有很多相似之处.
private void G_Click(object sender, EventArgs e)
{
if (go.Visible == true)
{
go.Visible = false;
Random rnd = new Random();
int y = rnd.Next(1, 7);
if (y == 1)
{
eo.Visible = true;
}
if (y == 2)
{
ao.Visible = true;
}
if (y == 4)
{ …Run Code Online (Sandbox Code Playgroud)