Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error:Segmentation fault (core dumped)

error:Segmentation fault (core dumped)

Scheduled Pinned Locked Moved C / C++ / MFC
helpasp-netlinuxdata-structuresdebugging
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Van Nguyen
    wrote on last edited by
    #1

    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.

    J 1 Reply Last reply
    0
    • V Van Nguyen

      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.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      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 line

      if( (img = cvLoadImage( filename, 1)) == 0 )

      where you are passing the char variable filename where a char * is expected.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups