error:Segmentation fault (core dumped)
-
When I am trying run program, command line for ubuntu generation error that. I'm trying run compline program with command:~/build/LSB/LSB$ ./thanhtmLSBext Girl.emb.bmp This is code of my: File c: thanhtmLSBext.c #include include include include include int *alloc_int_1D(int rows); void free_int_1D(int *array); int main(int argc, char** argv) { int i, j, n = 0; IplImage* img; FILE *fp; int fp_size; int wm; char filename = argc >= 2 ? argv[1] : (char*)"Girl.emb.jpg"; if( (img = cvLoadImage( filename, 1)) == 0 ) return -1; fp = fopen( "extract.gray", "wb" ); if( fp == NULL ) { puts( "extract.grayが開けません" ); return -1; } wm = (int *)alloc_int_1D(64*64*10); for(i = 0; i < 64*64*10; i++){ wm[i] = 0; } CvScalar s; int h=img->height; int w=img->width; for(i=0; i<w;> for(j=0; j<h;> s=cvGet2D(img,i,j); wm[n] = (int)(s.val[0])%2; fputc(wm[n]255,fp); n++; } } cvReleaseImage(&img); free_int_1D(wm); fclose(fp); return 1; } / IplImage* embed(IplImage *img, int wm, int N){ IplImage img1; int i, j, n = 0; img1 = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3); CvScalar s,s1; int h=img->height; int w=img->width; for(i=0; i<w;> for(j=0; j<h;> s=cvGet2D(img,i,j); s1.val[0]=s.val[0] + (double)wm[n%N]/255 - (double)((int)(s.val[0])%2); s1.val[1]=s.val[1]; s1.val[2]=s.val[2]; cvSet2D(img1,i,j,s1); n++; } } } */ int *alloc_int_1D(int rows) { int *p; p = (int *)malloc(rows * sizeof(int)); if (!p) { ifdef DEBUG fprintf(stderr, "alloc_int(): malloc() failed\n"); exit(1); else return NULL; endif } return p; } void free_int_1D(int *array) { free(array); } I hope everybody will help me. Thanks you.
-
When I am trying run program, command line for ubuntu generation error that. I'm trying run compline program with command:~/build/LSB/LSB$ ./thanhtmLSBext Girl.emb.bmp This is code of my: File c: thanhtmLSBext.c #include include include include include int *alloc_int_1D(int rows); void free_int_1D(int *array); int main(int argc, char** argv) { int i, j, n = 0; IplImage* img; FILE *fp; int fp_size; int wm; char filename = argc >= 2 ? argv[1] : (char*)"Girl.emb.jpg"; if( (img = cvLoadImage( filename, 1)) == 0 ) return -1; fp = fopen( "extract.gray", "wb" ); if( fp == NULL ) { puts( "extract.grayが開けません" ); return -1; } wm = (int *)alloc_int_1D(64*64*10); for(i = 0; i < 64*64*10; i++){ wm[i] = 0; } CvScalar s; int h=img->height; int w=img->width; for(i=0; i<w;> for(j=0; j<h;> s=cvGet2D(img,i,j); wm[n] = (int)(s.val[0])%2; fputc(wm[n]255,fp); n++; } } cvReleaseImage(&img); free_int_1D(wm); fclose(fp); return 1; } / IplImage* embed(IplImage *img, int wm, int N){ IplImage img1; int i, j, n = 0; img1 = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3); CvScalar s,s1; int h=img->height; int w=img->width; for(i=0; i<w;> for(j=0; j<h;> s=cvGet2D(img,i,j); s1.val[0]=s.val[0] + (double)wm[n%N]/255 - (double)((int)(s.val[0])%2); s1.val[1]=s.val[1]; s1.val[2]=s.val[2]; cvSet2D(img1,i,j,s1); n++; } } } */ int *alloc_int_1D(int rows) { int *p; p = (int *)malloc(rows * sizeof(int)); if (!p) { ifdef DEBUG fprintf(stderr, "alloc_int(): malloc() failed\n"); exit(1); else return NULL; endif } return p; } void free_int_1D(int *array) { free(array); } I hope everybody will help me. Thanks you.
char filename = argc >= 2 ? argv[1] : (char)"Girl.emb.jpg";
I stopped reading the unformatted code after this point but it is very probable that this is the reason for the segmentation fault. It should be:
const char * filename = argc >= 2 ? argv[1] : "Girl.emb.jpg";
I strongly recommend to use the
-Wall
GCC option when compiling and don't start the program while there are any warnings. Then you should have a got a lot of warnings with your code; at least in the next lineif( (img = cvLoadImage( filename, 1)) == 0 )
where you are passing the
char
variablefilename
where achar *
is expected.