fclose is causing a crash and works for less than 10k entries when commented. Could someone comment what...

What is the longest distance a 13th-level monk can jump while attacking on the same turn?

What is a Meta algorithm?

Is it true that "carbohydrates are of no use for the basal metabolic need"?

Is there a service that would inform me whenever a new direct route is scheduled from a given airport?

Why was the term "discrete" used in discrete logarithm?

Can a non-EU citizen traveling with me come with me through the EU passport line?

Can Pao de Queijo, and similar foods, be kosher for Passover?

3 doors, three guards, one stone

What makes black pepper strong or mild?

Should I use Javascript Classes or Apex Classes in Lightning Web Components?

Examples of mediopassive verb constructions

Right-skewed distribution with mean equals to mode?

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

Is there a Spanish version of "dot your i's and cross your t's" that includes the letter 'ñ'?

Models of set theory where not every set can be linearly ordered

What is this single-engine low-wing propeller plane?

Did Kevin spill real chili?

What are the pros and cons of Aerospike nosecones?

If Jon Snow became King of the Seven Kingdoms what would his regnal number be?

When to stop saving and start investing?

Do I really need recursive chmod to restrict access to a folder?

How can whole tone melodies sound more interesting?

Storing hydrofluoric acid before the invention of plastics

What are the motives behind Cersei's orders given to Bronn?



fclose is causing a crash and works for less than 10k entries when commented. Could someone comment what could be wrong with the below program



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)What could be causing the document reader to crash?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Here goes the program



1 #include
2 #include
3 #include
4
5
6 void main() {
7 FILE *fp;
8 char str[200];
9 char *tempstr;
10 char close[65000][10];
11 char open[65000][10];
12 char station[65000][20];
13 static int count;
14 int i=0,j=0;
15 tempstr=(char *)malloc(200);
16 bzero((void *)str,200);
17 system("$SHELL parselog.sh 52799272_LOG1");
18 do {
19 system("head -n 7 tempfile > temp");
20 fp=fopen("temp","r");
21 while((fgets(str,120,fp)) != NULL) {
22 if(strstr(str,"OPEN")!= NULL) {
23 strcpy(open[count],strtok(str," "));
24 printf("%sn",open[count]);
25 } else if(strstr(str,"CLOSE")!= NULL) {
26 strcpy(close[count],strtok(str," "));
27 printf("%sn",close[count]);
28 }
29 else if (strstr(str,"YOURHOSTNAME:")!= NULL) {
30 printf("%sn",str);
31 bzero((void *)tempstr,200);
32 strcpy(tempstr,str);
33 tempstr = strtok(tempstr," ");
34 printf("tempstr:%sn",tempstr);
35 tempstr = strtok(NULL," ");
36 printf("tempstr:%sn",tempstr);
37 strcpy(station[count],tempstr);
38 printf("%sn",station[count]);
39 count++;
40 bzero((void *)str,200);
41 break;
42 }
43 // printf("%sn",str);
44 bzero((void *)str,200);
45 }
46 system("cp tempfile tmp");
47 remove("tempfile");
48 system("tail -n +9 tmp > tempfile");
49 //fclose(fp);
50 fp=fopen("tmp","r");
51 fgets(str,120,fp);
52 fclose(fp);
53 remove("temp");
54 remove("tmp");
55 //i++;
56 }while(str != NULL);
57 //}while(i < 10000);
58 }



the fclose in line#49 is causing the issue when uncommented it crashes right after parsing 2 entries and when commented it crashes stating there are too many open files.



case 1:
free(): invalid pointer
Aborted (core dumped)



case 2:
cp: cannot create regular file 'tmp': Too many open files
sh: 1: 1: Too many open files
Segmentation fault (core dumped)



Could someone poit what is wrong with my program?









share





























    0















    Here goes the program



    1 #include
    2 #include
    3 #include
    4
    5
    6 void main() {
    7 FILE *fp;
    8 char str[200];
    9 char *tempstr;
    10 char close[65000][10];
    11 char open[65000][10];
    12 char station[65000][20];
    13 static int count;
    14 int i=0,j=0;
    15 tempstr=(char *)malloc(200);
    16 bzero((void *)str,200);
    17 system("$SHELL parselog.sh 52799272_LOG1");
    18 do {
    19 system("head -n 7 tempfile > temp");
    20 fp=fopen("temp","r");
    21 while((fgets(str,120,fp)) != NULL) {
    22 if(strstr(str,"OPEN")!= NULL) {
    23 strcpy(open[count],strtok(str," "));
    24 printf("%sn",open[count]);
    25 } else if(strstr(str,"CLOSE")!= NULL) {
    26 strcpy(close[count],strtok(str," "));
    27 printf("%sn",close[count]);
    28 }
    29 else if (strstr(str,"YOURHOSTNAME:")!= NULL) {
    30 printf("%sn",str);
    31 bzero((void *)tempstr,200);
    32 strcpy(tempstr,str);
    33 tempstr = strtok(tempstr," ");
    34 printf("tempstr:%sn",tempstr);
    35 tempstr = strtok(NULL," ");
    36 printf("tempstr:%sn",tempstr);
    37 strcpy(station[count],tempstr);
    38 printf("%sn",station[count]);
    39 count++;
    40 bzero((void *)str,200);
    41 break;
    42 }
    43 // printf("%sn",str);
    44 bzero((void *)str,200);
    45 }
    46 system("cp tempfile tmp");
    47 remove("tempfile");
    48 system("tail -n +9 tmp > tempfile");
    49 //fclose(fp);
    50 fp=fopen("tmp","r");
    51 fgets(str,120,fp);
    52 fclose(fp);
    53 remove("temp");
    54 remove("tmp");
    55 //i++;
    56 }while(str != NULL);
    57 //}while(i < 10000);
    58 }



    the fclose in line#49 is causing the issue when uncommented it crashes right after parsing 2 entries and when commented it crashes stating there are too many open files.



    case 1:
    free(): invalid pointer
    Aborted (core dumped)



    case 2:
    cp: cannot create regular file 'tmp': Too many open files
    sh: 1: 1: Too many open files
    Segmentation fault (core dumped)



    Could someone poit what is wrong with my program?









    share

























      0












      0








      0








      Here goes the program



      1 #include
      2 #include
      3 #include
      4
      5
      6 void main() {
      7 FILE *fp;
      8 char str[200];
      9 char *tempstr;
      10 char close[65000][10];
      11 char open[65000][10];
      12 char station[65000][20];
      13 static int count;
      14 int i=0,j=0;
      15 tempstr=(char *)malloc(200);
      16 bzero((void *)str,200);
      17 system("$SHELL parselog.sh 52799272_LOG1");
      18 do {
      19 system("head -n 7 tempfile > temp");
      20 fp=fopen("temp","r");
      21 while((fgets(str,120,fp)) != NULL) {
      22 if(strstr(str,"OPEN")!= NULL) {
      23 strcpy(open[count],strtok(str," "));
      24 printf("%sn",open[count]);
      25 } else if(strstr(str,"CLOSE")!= NULL) {
      26 strcpy(close[count],strtok(str," "));
      27 printf("%sn",close[count]);
      28 }
      29 else if (strstr(str,"YOURHOSTNAME:")!= NULL) {
      30 printf("%sn",str);
      31 bzero((void *)tempstr,200);
      32 strcpy(tempstr,str);
      33 tempstr = strtok(tempstr," ");
      34 printf("tempstr:%sn",tempstr);
      35 tempstr = strtok(NULL," ");
      36 printf("tempstr:%sn",tempstr);
      37 strcpy(station[count],tempstr);
      38 printf("%sn",station[count]);
      39 count++;
      40 bzero((void *)str,200);
      41 break;
      42 }
      43 // printf("%sn",str);
      44 bzero((void *)str,200);
      45 }
      46 system("cp tempfile tmp");
      47 remove("tempfile");
      48 system("tail -n +9 tmp > tempfile");
      49 //fclose(fp);
      50 fp=fopen("tmp","r");
      51 fgets(str,120,fp);
      52 fclose(fp);
      53 remove("temp");
      54 remove("tmp");
      55 //i++;
      56 }while(str != NULL);
      57 //}while(i < 10000);
      58 }



      the fclose in line#49 is causing the issue when uncommented it crashes right after parsing 2 entries and when commented it crashes stating there are too many open files.



      case 1:
      free(): invalid pointer
      Aborted (core dumped)



      case 2:
      cp: cannot create regular file 'tmp': Too many open files
      sh: 1: 1: Too many open files
      Segmentation fault (core dumped)



      Could someone poit what is wrong with my program?









      share














      Here goes the program



      1 #include
      2 #include
      3 #include
      4
      5
      6 void main() {
      7 FILE *fp;
      8 char str[200];
      9 char *tempstr;
      10 char close[65000][10];
      11 char open[65000][10];
      12 char station[65000][20];
      13 static int count;
      14 int i=0,j=0;
      15 tempstr=(char *)malloc(200);
      16 bzero((void *)str,200);
      17 system("$SHELL parselog.sh 52799272_LOG1");
      18 do {
      19 system("head -n 7 tempfile > temp");
      20 fp=fopen("temp","r");
      21 while((fgets(str,120,fp)) != NULL) {
      22 if(strstr(str,"OPEN")!= NULL) {
      23 strcpy(open[count],strtok(str," "));
      24 printf("%sn",open[count]);
      25 } else if(strstr(str,"CLOSE")!= NULL) {
      26 strcpy(close[count],strtok(str," "));
      27 printf("%sn",close[count]);
      28 }
      29 else if (strstr(str,"YOURHOSTNAME:")!= NULL) {
      30 printf("%sn",str);
      31 bzero((void *)tempstr,200);
      32 strcpy(tempstr,str);
      33 tempstr = strtok(tempstr," ");
      34 printf("tempstr:%sn",tempstr);
      35 tempstr = strtok(NULL," ");
      36 printf("tempstr:%sn",tempstr);
      37 strcpy(station[count],tempstr);
      38 printf("%sn",station[count]);
      39 count++;
      40 bzero((void *)str,200);
      41 break;
      42 }
      43 // printf("%sn",str);
      44 bzero((void *)str,200);
      45 }
      46 system("cp tempfile tmp");
      47 remove("tempfile");
      48 system("tail -n +9 tmp > tempfile");
      49 //fclose(fp);
      50 fp=fopen("tmp","r");
      51 fgets(str,120,fp);
      52 fclose(fp);
      53 remove("temp");
      54 remove("tmp");
      55 //i++;
      56 }while(str != NULL);
      57 //}while(i < 10000);
      58 }



      the fclose in line#49 is causing the issue when uncommented it crashes right after parsing 2 entries and when commented it crashes stating there are too many open files.



      case 1:
      free(): invalid pointer
      Aborted (core dumped)



      case 2:
      cp: cannot create regular file 'tmp': Too many open files
      sh: 1: 1: Too many open files
      Segmentation fault (core dumped)



      Could someone poit what is wrong with my program?







      crash





      share












      share










      share



      share










      asked 2 mins ago









      SomsSoms

      1




      1






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1134228%2ffclose-is-causing-a-crash-and-works-for-less-than-10k-entries-when-commented-co%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1134228%2ffclose-is-causing-a-crash-and-works-for-less-than-10k-entries-when-commented-co%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Is there a lightweight tool to crop images quickly?Cropping Images using Command Line Tools OnlyHow to crop...

          List of shipwrecks in 1808...

          Unit packagekit.service is masked Announcing the arrival of Valued Associate #679: Cesar...