我正在用bash编写脚本,我收到此错误:
./P4.1: line 10: +: syntax error: operand expected (error token is "+")
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
#!/bin/bash
read string
echo $string >| temp
num1= cut -d" " -f1 temp
num2= cut -d" " -f2 temp
num3= cut -d" " -f3 temp
while [ $num1 -gt $num3 ]
do
echo $num1
num1=$[$num1+$num2]
done
Run Code Online (Sandbox Code Playgroud)
怎么了,怎么解决?谢谢.
我是C的新手.我正在尝试从用户那里获取大量文本,并计算单词,字符,行,空格和字母的数量.这就是我所做的:
#include <ctype.h>
#include <stdio.h>
int main(void)
{
char c = getchar();
char previousc;
int charcount = 0;
int wordcount = 0;
int whitespacecount = 0;
int linecount = 0;
int lettercount = 0;
while(c != EOF)
{
if(isLetter(c) == 1) lettercount++;
if(isWhitespace(c) == 1)
{
whitespacecount++;
if(isWhitespace(previousc) == 0) wordcount++;
}
if(c == "\n") linecount++;
previousc = c;
c = getchar();
charcount++;
}
printf("Character Count: %d\n Word Count: %d\n Whitespace Count: %d\n Letter Count: %d\n Line Count: %d\n", charcount, …Run Code Online (Sandbox Code Playgroud) 我想实例化ArrayLists的ArrayList(泛型类型).我有这个代码:
private ArrayList<ArrayList<GameObject>> toDoFlags;
toDoFlags = new ArrayList<ArrayList<GameObject>>(2);
Run Code Online (Sandbox Code Playgroud)
我这样做了吗?它编译,但是当我查看ArrayList时,它的大小为0.
我有一个字符串数组,我想检查字符串是否为数字,然后将其作为整数放入对象数组。
(对于那些问为什么要使用对象数组的人,因为我也想检查字符和其他内容)
我有这个:
Console.WriteLine("Enter parameters for the function with a space in between each parameter: "); String stringParameters = Console.ReadLine();
String[] parametersStringArray = stringParameters.Split(' ');
Object[] parametersArray = new Object[parametersStringArray.Length];
for (int i = 0; i < parametersStringArray.Length; i++)
{
int.TryParse(parametersStringArray[i], out int.Parse(parametersArray[i]));
}
Run Code Online (Sandbox Code Playgroud)
它无法编译,并且我对'out'命令不熟悉,出了什么问题以及如何解决?
谢谢。
我在类中有很多静态方法,如果某个方法在X类中,我想得到它,如果是,我想调用它.我查了一下:
if (Type.GetType("Homework.Homework.Functions").GetMethod(methodName) == null)
{
Console.WriteLine("No such method.\nPress any key to restart the program");
Console.ReadKey();
Console.Clear();
Main();
return;
}
else
Type.GetType("Homework.Homework.Functions").GetMethod(methodName).Invoke(null, parametersArray); // Invoking the method.
Run Code Online (Sandbox Code Playgroud)
但是它给了我一个带有if()的行中的System.NullReferenceException.
该计划的开始:
namespace Homework
{
class Homework
{
static void Main()
{
Run Code Online (Sandbox Code Playgroud)
课堂宣言:
public class Functions
{
Run Code Online (Sandbox Code Playgroud)
我可能应该说类函数在类Homework中.
我该如何解决这个错误?
谢谢.
我正在尝试在C中编写一个获取字节(char)和索引的宏,然后index从该字节读取该位.这就是我得到的:
#define READBIT(byte, index) (byte) & (1 << (index))
Run Code Online (Sandbox Code Playgroud)
这就是我检查它的方式:
for (i = 7; i >= 0; i--)
{
printf("%d", READBIT('a', i));
}
Run Code Online (Sandbox Code Playgroud)
它打印0643200001.
为什么不工作,我该如何解决?
我有一个像这样的循环:
for(i = 0; i < arrayLength; i++)
{
result[i / 8] = SETBIT(result[i / 8], ++(*bitIndex), array[i]);
*bitIndex %= 8;
}
Run Code Online (Sandbox Code Playgroud)
我想知道什么是更好的,性能方面,如果我使用上面的风格,或这种风格:
for(i = 0; i < arrayLength; i++)
{
result[i / 8] = SETBIT(result[i / 8], ++(*bitIndex), array[i]);
if(*bitIndex == 8) *bitIndex = 0;
}
Run Code Online (Sandbox Code Playgroud)
这是在C中,用GCC编译,也可以理解.
谢谢
我正在尝试用C++编写矩阵结构,我是一个新手.mat4.h文件:
#include "math.h"
namespace engine {
namespace math {
struct mat4 {
float elements[4 * 4]; // column major ordering, index = row + col * 4
mat4();
mat4(float diagonal);
mat4& mul(const mat4& other);
static mat4 identity(); // construct and return an identity matrix
static mat4 orthographic(float left, float right, float bottom, float top, float near, float far); // boundaries (clipping planes)
static mat4 perspective(float fov, float aspectRatio, float near, float far);
static mat4 translation(const vec3& translation);
static mat4 rotation(float …Run Code Online (Sandbox Code Playgroud) 我正在用C进行生活游戏.我正在检查一个单元格是否存活(使用DEAD或ALIVE的typedef调用状态),然后查看其邻居的事情.如果它已经死了,我正在检查它是否应该生活在下一代.问题是它不起作用,当我在gdb中调试程序时,似乎忽略了我的else语句.这是我的代码的相关部分:
#include <stdio.h>
#include <stdlib.h>
#define maxHeight 10
#define maxWidth 10
#define maxGenerations 100
typedef enum { DEAD, ALIVE } state;
void nextGeneration(state[][maxHeight][maxWidth], int, int, int);
int numberOfNeighbours(state[][maxHeight][maxWidth], int, int, int);
void printGeneration(state[][maxHeight][maxWidth], int, int, int);
void nextGeneration(state board[][maxHeight][maxWidth], int requestedGeneration, int boardHeight, int boardWidth)
{
int h;
int w;
int currentNumOfNeighbours;
for(h = 0; h < boardHeight; h++)
for(w = 0; w < boardHeight; w++)
{
currentNumOfNeighbours = numberOfNeighbours(board, requestedGeneration, h, w);
if(board[requestedGeneration][h][w] == ALIVE)
{
if(currentNumOfNeighbours == 2 …Run Code Online (Sandbox Code Playgroud)