Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9288651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:57:39+00:00 2026-06-18T19:57:39+00:00

When my program gets to the return 0 in main the program exits, but

  • 0

When my program gets to the return 0 in main the program exits, but control does not return to the command line. I have even tried exit(), to no avail. Any suggestions

int main (int argc, char* argv[])
{

    char name[100];
    char reg[200];
    char replace[200];

    if(argc==3){
        strcpy(reg, ".*");
        strcat(reg, argv[1]);
        strcat(reg, ".*");
    }
    else if(argc==4){

        strcpy(reg, "\\(\\(.*");
        strcat(reg, argv[3]);
        strcat(reg, ".*");
        strcat(reg, argv[1]);
        strcat(reg, ".*\\)\\|\\(.*");
      strcat(reg, argv[1]);
      strcat(reg, ".*");
      strcat(reg, argv[3]);
      strcat(reg, ".*\\)\\)");

        printf("\n%s\n", reg);
//        exit(1);
    }
    printf("\n%s\n", reg);

    strcpy(name, argv[1]);
    strcpy(replace, argv[2]);
    printf("\n%s\n", name);
//  puts(realpath("./b/test2",NULL));
    int reti;
    char msgbuf[100];
    regex_t regex;
   /* Compile regular expression */
   reti = regcomp(&regex, reg, 0);
   if( reti ){ fprintf(stderr, "Could not compile regex\n"); exit(1); }

    list_dir (".", regex, name, replace);


    char line[BUFSIZ];
    FILE *fp2=fopen("source.dat","r");

    if(fp2==NULL)
        printf("Problm opening: source.dat");

    FILE *fp3=fopen("result.dat", "r");
    if(fp3==NULL)
        printf("Problm opening: result.dat");
    char line2[1000];
    int len;

    while( (fgets(line2, BUFSIZ, fp2) != NULL) && (fgets(line, BUFSIZ, fp3) != NULL)) {
        len=strlen(line);
        if( line[len-1] == '\n' )
            line[len-1] = '\0';
        len=strlen(line2);
        if( line2[len-1] == '\n' )
            line2[len-1] = '\0';

        rename(line, line2);
    }

    close(fp2);
    free(fp2);
    close(fp3);
    free(fp3);
    remove("source.dat");
    remove("result.dat");
    regfree(&regex);
   return 0;
}

My program does what I intend it to do, but when it finishes the while loop and frees everything, control does not go back to command line without pressing ctr-C. Still stumped on why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:57:41+00:00Added an answer on June 18, 2026 at 7:57 pm

    Well, it’s hard to say without a complete program. Based on the code that’s presented, the most obvious bug that jumps out is the file handle usage. The API works like this: you allocate a FILE* by calling fopen(), you deallocate it by calling fclose(). Instead, you are calling close() on a FILE* and then (!) passing it to free().

    I’m not sure what exact language/version you’re using, but probably your compiler could have helped you find this problem if you had asked for more error checking. For example, gcc with -Wall would warn that it had to use implicit declarations for close(), free(), etc. After adding in the correct header files (so it can see the prototype declarations for the functions you’re using), it would then say things like:

     warning: passing arg 1 of `close' makes integer from pointer without a cast
    

    giving you a clue that you’re using close() incorrectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that gets a JSON from the server using getJSON and
I have a program that gets the FOV angle of the device's rear-facing camera,
I have a program that calls a rest service and gets back a string
I have made a program that gets some strings in input from the user
I have a program that gets a KERN_PROTECTION_FAILURE with EXC_BAD_ACCESS in a very strange
I have an object which does some work in an endless loop. The main()
i am using openmp in fortran and before the program gets much done at
I've wrote a program that gets a string, and then calculate a total value
I am supposed to write a program that gets some PNG images from the
I am writing a small program that gets activated when sms is received.We need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.