我试图在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中读取文件的指南.
我必须编写一个具有外部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.h和convertAll.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) 我刚刚使用以下代码删除了数组中的元素:
delete chckboxIDs[0][0];
Run Code Online (Sandbox Code Playgroud)
这就是我的数组中的数据现在的样子:
现在我的数组有一个空单元格,它打破了代码,因为我根据程序中其他位置的长度循环它,导致空值异常.我如何摆脱这个空旷的空间?
如果我将所有元素向下移动直到它处于最后位置,它仍然会在那里并仍然破坏代码?有一个更好的方法吗?