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. help about this stack overflow?

help about this stack overflow?

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresquestion
2 Posts 2 Posters 0 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.
  • W Offline
    W Offline
    wendyyue
    wrote on last edited by
    #1

    #include #include int min(int a, int b, int c) { int temp=a<=b?a:b; return temp<=c?temp:c; } int MinOperation(int len1, char str1[], int len2, char str2[]) { int count[10001][10001]; int i,j; for(i=0; i<1001; i++) count[0][i]=0; for(i=0; i<1001; i++) count[i][0]=0; for(i=1; i<=len1; i++) for(j=1; j<=len2; j++) { if(str1[i]==str2[j]) count[i][j]=min( count[i-1][j-1], count[i-1][j]+1, count[i][j-1]+1); else count[i][j]=min( count[i-1][j-1]+1, count[i][j-1]+1, count[i-1][j]+1 ); } return count[len1][len2]; } void main() { int i=0; int len1; int len2; char str1[1001]; char str2[1001]; scanf("%d%s", len1, (str1) ); scanf("%d%s", len2, (str2) ); puts(str1); puts(str2); printf("%d", MinOperation(len1 ,str1 ,len2 ,str2)); } I am not sure why there exist a bug stack overflow?

    R 1 Reply Last reply
    0
    • W wendyyue

      #include #include int min(int a, int b, int c) { int temp=a<=b?a:b; return temp<=c?temp:c; } int MinOperation(int len1, char str1[], int len2, char str2[]) { int count[10001][10001]; int i,j; for(i=0; i<1001; i++) count[0][i]=0; for(i=0; i<1001; i++) count[i][0]=0; for(i=1; i<=len1; i++) for(j=1; j<=len2; j++) { if(str1[i]==str2[j]) count[i][j]=min( count[i-1][j-1], count[i-1][j]+1, count[i][j-1]+1); else count[i][j]=min( count[i-1][j-1]+1, count[i][j-1]+1, count[i-1][j]+1 ); } return count[len1][len2]; } void main() { int i=0; int len1; int len2; char str1[1001]; char str2[1001]; scanf("%d%s", len1, (str1) ); scanf("%d%s", len2, (str2) ); puts(str1); puts(str2); printf("%d", MinOperation(len1 ,str1 ,len2 ,str2)); } I am not sure why there exist a bug stack overflow?

      R Offline
      R Offline
      Rajkumar R
      wrote on last edited by
      #2

      wendyyue wrote:

      scanf("%d%s", **&**len1, (str1) ); scanf("%d%s", **&**len2, (str2) );

      if you specified parameters for scanf correctly, the above, then the stack overflow is due to the stack allocation int count[10001][10001]; which is "10001 * 10001 * sizeof (int)" which is very large than the default stack size which is 1MB. To increase the stack size /STACK (Stack Allocations)[^]. It is better to allocate in heap. And also array size in main 1001 and size in MinOperation 10001 check it for logic of your program (Any way int count[1001][1001] is also going to issue stack overflow).

      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