小编Som*_*ude的帖子

Perl - 读取文本文件时出错

我试图在perl中读取一个文件.

我只想打印每行文件的名称players.txt.

我正在使用此代码:

#!/usr/local/bin/perl
open (MYFILE, 'players.txt');
while () {
    chomp;
    print "$_\n";
}
close (MYFILE);
Run Code Online (Sandbox Code Playgroud)

这会产生此错误:

./program5.pl: line 2: syntax error near unexpected token `MYFILE,'
./program5.pl: line 2: `    open (MYFILE, 'players.txt');'
Run Code Online (Sandbox Code Playgroud)

我正在使用Unix操作系统来执行此操作.我找不到适用于在Perl中读取文件的指南.

perl

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

编译C程序,同时在gcc中包含.h文件

我必须编写一个具有外部C文件的程序.我最初在Visual Studio中编写了这个程序,但我现在必须切换到gccLinux.我包含了.h允许我在另一个C文件中调用函数的文件.这适用于Visual Studio,但gcc不接受该引用.它在尝试调用函数时中断convertAllStrings(c,size).

错误是: undefined reference to `convertAllStrings'

我在Google上搜索过,发现有些人说这个问题我应该使用这个gcc -I命令.我试过这个,但没有运气.具体我用过:

gcc -I/home/CS/user/unix Main.c -o proj
Run Code Online (Sandbox Code Playgroud)

我有Main.C,convertAll.hconvertAll.c,在同一目录中.这是我的代码:

文件Main.c:

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>

#include "convertAll.h"

int main(int ac, char *av[])
{
    int size;
    char strings[100];
    char temp;

    printf("Number of Strings: ");
    scanf("%d", &size);
    char **c = malloc(size);

    int i = 0;
    int j = 0;
    while (i < size)
    { …
Run Code Online (Sandbox Code Playgroud)

c gcc

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

从多维数组中删除元素的最佳方法 - JavaScript

我刚刚使用以下代码删除了数组中的元素:

delete chckboxIDs[0][0];
Run Code Online (Sandbox Code Playgroud)

这就是我的数组中的数据现在的样子:

在此输入图像描述

现在我的数组有一个空单元格,它打破了代码,因为我根据程序中其他位置的长度循环它,导致空值异常.我如何摆脱这个空旷的空间?

如果我将所有元素向下移动直到它处于最后位置,它仍然会在那里并仍然破坏代码?有一个更好的方法吗?

javascript multidimensional-array

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

标签 统计

c ×1

gcc ×1

javascript ×1

multidimensional-array ×1

perl ×1