我很新于Linux的使用和C语言的编程。我一直试图创建一个简单压缩字符串的程序,但是当我尝试运行编译后的文件时,总是得到“Segmentation fault”的错误。 我使用以下命令编译:
gcc 2.c -o test.o -lz
我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#include <assert.h>
int main ()
{
char *istream = malloc(10), *ostream = malloc(120);
istream = "istream";
int res = compress(ostream, (uLongf *)strlen(ostream), istream,(ulong)strlen(istream));
return 0;
}
有人能够解释一下为什么会出现这个错误,以及我应该如何改进我的代码吗?
C++
标签? - Sourav Ghosh