我试图通过malloc(),realloc()释放()所有分配的内存,但valgrind说这是一个内存泄漏.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
int lines_allocated = 128;
int max_line_len = 50;
FILE *fp;
/* File allocate lines of text */
char **array = (char **)malloc(sizeof(char*)*lines_allocated);
if (array==NULL) {
fprintf(stderr,"Out of memory (1).\n");
exit(1);
}
FILE *file = fopen("file.txt", "r");
if (file == NULL) {
fprintf(stderr,"Error opening file.\n");
exit(2);
}
int il;
for (il = 0; 1; il++) {
int j;
/* Have we gone over our line allocation? */ …Run Code Online (Sandbox Code Playgroud) 我正在使用Ubuntu Server 14.04.我需要使用./configure --enable-unicode = ucs4选项来创建我的新django项目python.我用ucs4重新安装了python.
现在,当我试图运行scrapy spider时,我收到如下错误:
ImportError: /usr/local/lib/python2.7/site-packages/lxml-3.4.2-py2.7-linux-x86_64.egg/lxml/etree.so: undefined symbol: PyUnicodeUCS2_DecodeLatin1
Run Code Online (Sandbox Code Playgroud)
然后我试图再次重新安装python但出现错误:
Compiling /usr/local/lib/python2.7/zipfile.py ...
make: *** [libinstall] Error 1
Run Code Online (Sandbox Code Playgroud)
然后我试图重新安装libxml,但也有错误:
/usr/bin/ld: /usr/local/lib/python2.7/config/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/python2.7/config/libpython2.7.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
Scrapy重新安装没有帮助.
请帮忙!
在C中将变量插入指针数组(插入第二维)的最有效方法是什么?像这样:
char * get_time(void)
{
time_t rawtime;
struct tm * ptm;
time (&rawtime);
ptm = gmtime ( &rawtime );
ptm->tm_hour = ptm->tm_hour - 4;
return asctime(ptm);
}
char *some_array[] = {
"some" get_time() "string",
"some string"
}
Run Code Online (Sandbox Code Playgroud)