我似乎无法解决这个问题.以下是我的代码:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
_Bool are_anagrams (const char *word1, const char *word2);
int main (void)
{
char an1[30], an2[30];
int j;
printf("Enter first word: ");
scanf("%s", an1);
printf("Enter second word: ");
scanf("%s", an2);
printf("The words are");
j = are_anagrams (an1, an2);
if (j == 0)
{
printf(" not anagrams. \n");
}else
printf(" anagrams. \n");
return 0;
}
_Bool are_anagrams (const char *word1, const char *word2)
{
int i;
int check[26] = {0};
for(i=0; i<30; i++)
if(word1[i] == '\0')
i=40;
else …Run Code Online (Sandbox Code Playgroud) 是否可以在C中的FILE构造之后声明的文件名内传递变量的值?
我的目的是在下面的代码片段中将变量w的值打印在文件名中:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "nr.h"
#include "nrutil.h"
double h = 0.01;
double w = 5.0;
int main(void)
{
FILE * fp = fopen("q1function_W_VALUEHERE.dat","w+");
/* The point I would like to have the value of w printed */
for(i = 0; i < N; i++)
{
t[i] = i * h;
y[i] = func(t[i]);
fprintf(fp, "%f \t %f \n", t[i], y[i]);
}
fclose(fp);
return 0;
}
int i = 42;
char fname[PATH_MAX];
snprintf(fname, PATH_MAX, "file_%d.txt", i); …Run Code Online (Sandbox Code Playgroud) 如何在C#中将数组转换为某种大小的数组列表?
例如:
byte[] incoming = {1,2,3,4};
List<byte[]> chunks = new List<byte[]>;
Run Code Online (Sandbox Code Playgroud)
我想要的是这样的东西,得到一些大小,下面我用2.
chunks[0] = {1,2};
chunks[1] = {3,4};
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在理解strcmp函数的奇怪行为,将通过以下代码进行说明:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char *p = "no";
cout << p << endl; //Output: no
cout << &p << endl; //Output: 0x28ac64
cout << strlen(p) << endl; //Output: 2
cout << strcmp(p, "no") << endl; //Output: 0
cin >> p; //Input: bo
cout << p << endl; //Output: bo
cout << &p << endl; //Output: 0x28ac64
cout << strlen(p) << endl; //Output: 2
cout << strcmp(p, "no") << endl; //Output: 0 …Run Code Online (Sandbox Code Playgroud) 我想访问类内部列表中的类成员值.我的课程看起来像这样.的SureViewEvents类包含一个进入报警父级别的细节和SureViewEventDetails用于报警的细节的值.我想SureViewEvents使用LINQ 循环遍历类,并循环遍历详细信息行(如果有任何填充).
我该怎么做呢?
public class SureViewEvents
{
public string EventId { get; set; }
public string GroupId { get; set; }
public string DateTimeCreated { get; set; }
public string GroupTitle { get; set; }
public string EventTitle { get; set; }
public string SubscriberId { get; set; }
public bool Closed { get; set; }
public List<SureViewEventDetails> Details { get; set; }
}
//EventID|EventRecordID|CreatedDate|EventRecordTypeID|Details|Input1|Input2|EventCode|SubscriberID|EventTitle|SerialNo
public class SureViewEventDetails
{
public string EventId { get; …Run Code Online (Sandbox Code Playgroud) 我可以在定义后不使用范围(::)来定义类构造函数吗?
我会换一种说法,我可以把构造函数放在类定义中吗???
与此类似的东西:
MyClass {
public:
int attribute1;
...
MyClass(int a) {
attrbute1 = a;
}
};
Run Code Online (Sandbox Code Playgroud) 我可以连接下面的查询吗?如果不是,我该怎么办?我不想读取行,$retrieveUnitExist因为它浪费了另一步.
$retrieveUnitExist = "SELECT unitid FROM ESTATEUNIT WHERE BLOCK = 1";
$insertAddress = "INSERT INTO ADDRESS (value1, value2) VALUES ('1','".$retrieveUnitExist."')";
mysqli_query($conn, $insertAddress);
Run Code Online (Sandbox Code Playgroud) 今天我注意到我的代码中有一个错误,我以为我是在不久前处理过的.我正在处理Windows Forms应用程序,我form_load经常使用该事件.为了处理Form_load事件中出现错误并抛出异常的情况,我使用以下代码:
catch (Exception ex)
{
LogErrorAndShowMessage(ex, Resources.ERROR_LOAD);
//Otherwise Error : "Cannot call Close() while doing CreateHandle()".
this.BeginInvoke(new InvokeDelegate(CloseTheForm));
LoadForm<Materials>(closeAlreadyOpened : false);
}
Run Code Online (Sandbox Code Playgroud)
这就是我如何声明委托和方法:
public delegate void InvokeDelegate();//used if form load fails
private void CloseTheForm()
{
this.Close();
}
Run Code Online (Sandbox Code Playgroud)
从今天起它运作良好.发生了什么 - 在Form_load我设置DataSource我的ComboBoxes 的事件中,碰巧从SetDataSource方法中抛出了一个错误,最终得到的错误与我在使用之前得到的相同BeginInvoke- Cannot call Close() while doing CreateHandle().
这是一种例外行为,如果从其他地方抛出异常代码仍然正常工作,只有在设置数据源期间我得到了错误.
任何可能导致这种异常行为的建议以及如何解决?
PS
这就是我创建新表单的方式:
protected void LoadForm<T>(ToolStripButton/*ToolStripDropDownButton*/ formButton,
string buttonText,
long? loadEntityId = null,
bool closeAlreadyOpened = …Run Code Online (Sandbox Code Playgroud) 问题如下
写一个程序,提示用户输入员工每小时的工资,当前工作小时数,并计算他的周薪.如果他的工作时间超过40小时,他每小时的工资是每小时超过40小时的原始工资的1.5倍.从工资总额中,6%用于社会保障税,14%用于所得税,10欧元用于工会.如果员工有两个以上的孩子,他需要支付35欧元的健康保险.计算他的周薪.
我的代码
#include "stdafx.h"
#include "iostream"
using namespace std;
int main()
{
double a,b,c,kid;
cout << "Enter his salary per hour: " << endl;
cin >> a;
cout << "Enter the amount of hours he worked this week: " << endl;
cin >> b;
cout << "How many kids does he have: " << endl;
cin >> kid;
if ( a > 40 ) {
if (kid > 2) {
b = (b-40)*1.5+40;
c = a*b-a*b*20/100-10-35;
}
else { …Run Code Online (Sandbox Code Playgroud) 这是带有相关错误的make命令:
g++ -g -O2 -Wl,-rpath=../../../external/boost-1.55.0-x86_64-linux-gcc-4.8.2/lib -pthread -o xml_wrapper_tester xml_wrapper_tester-runner.o -L../../../external/boost-1.55.0-x86_64-linux-gcc-4.8.2/lib -lboost-system ../xml_wrapper/.libs/libxml_wrapper.a -pthread
/usr/bin/ld: cannot find -lboost-system
Run Code Online (Sandbox Code Playgroud)
进入make文件所在的目录和ls -l指定-L的路径显示该库存在.
[mehoggan@localhost xml_wrapper_tester]$ ls -l ../../../external/boost-1.55.0-x86_64-linux-gcc-4.8.2/lib | grep system
-rw-rw-r--. 1 mehoggan mehoggan 217676 May 5 22:37 libboost_filesystem.a
lrwxrwxrwx. 1 mehoggan mehoggan 29 May 5 22:37 libboost_filesystem.so -> libboost_filesystem.so.1.55.0
-rwxrwxr-x. 1 mehoggan mehoggan 116955 May 5 22:37 libboost_filesystem.so.1.55.0
-rw-rw-r--. 1 mehoggan mehoggan 49154 May 5 22:37 libboost_system.a
lrwxrwxrwx. 1 mehoggan mehoggan 25 May 5 22:37 libboost_system.so -> libboost_system.so.1.55.0
-rwxrwxr-x. 1 mehoggan mehoggan …Run Code Online (Sandbox Code Playgroud) 您好,有人可以向我解释为什么当我运行程序时,该代码为什么在命令提示符下显示为(00 11 21 32 42)?
这是代码:
int main()
{
int x = 0;
int y = 0;
while (x < 5) {
y = x - y;
printf("%i%i ", x, y);
x = x + 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
谢谢。