小编sho*_*ham的帖子

语法错误:操作数预期(错误标记为"+")

我正在用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)

怎么了,怎么解决?谢谢.

unix bash

11
推荐指数
2
解决办法
7万
查看次数

C - 函数的错误冲突类型

我是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)

c

7
推荐指数
1
解决办法
7万
查看次数

实例化ArrayLists的ArrayList

我想实例化ArrayLists的ArrayList(泛型类型).我有这个代码:

private ArrayList<ArrayList<GameObject>> toDoFlags;
toDoFlags = new ArrayList<ArrayList<GameObject>>(2);
Run Code Online (Sandbox Code Playgroud)

我这样做了吗?它编译,但是当我查看ArrayList时,它的大小为0.

java arraylist

2
推荐指数
1
解决办法
843
查看次数

int.TryParse解析为对象数组

我有一个字符串数组,我想检查字符串是否为数字,然后将其作为整数放入对象数组。

(对于那些问为什么要使用对象数组的人,因为我也想检查字符和其他内容)

我有这个:

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'命令不熟悉,出了什么问题以及如何解决?

谢谢。

c# arrays

2
推荐指数
1
解决办法
4283
查看次数

Type.getType()找不到该类

我在类中有很多静态方法,如果某个方法在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# null gettype

2
推荐指数
1
解决办法
1648
查看次数

用于阅读的宏不起作用

我正在尝试在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.

为什么不工作,我该如何解决?

c macros

1
推荐指数
1
解决办法
498
查看次数

Modulu vs循环中的if语句

我有一个像这样的循环:

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 c++

0
推荐指数
1
解决办法
98
查看次数

没有参数的构造函数不起作用,但一个工作

我正在尝试用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++

0
推荐指数
1
解决办法
2436
查看次数

编译器忽略我的else语句

我正在用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)

c

-1
推荐指数
1
解决办法
86
查看次数

标签 统计

c ×4

c# ×2

c++ ×2

arraylist ×1

arrays ×1

bash ×1

gettype ×1

java ×1

macros ×1

null ×1

unix ×1