Run with no user intervention

This is a discussion on Run with no user intervention within the C Programming forums, part of the General Programming Boards category; I have a program which generates some files, when it has completed the console window requires the user to press ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    16

    Run with no user intervention

    I have a program which generates some files, when it has completed the console window requires the user to press a key (this isnt coded n, it seemingly is part of the the console).

    Is there a way to turn this off i.e. so the program runs and closes down cleanly?

    Code:
    #include <stdio.h>
    
    typedef struct {
      char char3[3];
      char newline;
    }record;
    
    int main(void) {
      FILE *fpin3, *fpin6, *fpout;
      int i;
      const char *filename6="master_dic.txt"; //reminder to take the newline char #6
      const char *filename3="3_character_append.txt";//leave the newline behind
      char fileOut[]="dic1.txt";
      record rec;
      char char6[6];
      unsigned long int count = 0;
    
      fpin3 = fopen(filename3, "rt");
      fpin6 = fopen(filename6, "rt");
      if(fpin3 == NULL || fpin6 == NULL) {
        printf("\nError opening input files");
        return 1;
      }
      if((fpout =fopen(fileOut, "wb"))== NULL) {
        printf("\nError opening output file");
        return 1;
      }
      printf("\n\n\n");
      for(i=0;i<5;i++) {
        fread(&rec, sizeof(rec), 1, fpin3);
    
        while(fread(char6, 6, 1, fpin6) >0) {
          fwrite(char6, 5, 1, fpout);          //ditto
          fwrite(rec.char3, 3, 1, fpout);     //fpout or stdout (for debug)
          fwrite("\n", 1, 1, fpout);
          ++count;
          //getch();
        }
        if(fileOut[3]=='5')
          break;
        rewind(fpin6);
        fclose(fpout);
        printf("\n closing file %s", fileOut);
        fileOut[3]++; //increment the file number in the name
        printf("\n opening file %s", fileOut);
        if((fpout =fopen(fileOut, "wb"))== NULL) {
          printf("\nError opening output file");
          return 1;
        }
      }
      /*fcloseall();*/
      /*printf("\n\n %lu\n\t\t\t    press enter when ready", count);*/
      /*getchar();*/
    
      /*i=getchar();*/
      return 0;
    }

  2. #2
    a guy with long hair Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    103
    Are you running your application from IDE by some Run button or in the terminal directly?

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    16
    I am calling the "exe" file from a batch file. Does that answer your question?

    I have tried compiling using different projects but all seem to give the same result in that the user has to press a key to exit the console window, this will then allow the batch file to continue.....

    There must be a way to write a C program which doesnt require a user input to end the process......

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It's not C that is holding the console window open, that's purely Window's. That program closes immediately for me, from both the command line, and from a bat file.

    No luck finding info on Google's links to it?

    Have you tried using Tskill or Taskkill?

    http://commandwindows.com/taskkill.htm
    Last edited by Adak; 09-24-2010 at 07:17 AM.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What does the .bat file look like?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  6. #6
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    You can put in an exit(0).
    -- Will you show me how to c++?

  7. #7
    Registered User
    Join Date
    Sep 2010
    Location
    Halesowen, England
    Posts
    30
    Quote Originally Posted by cpjust View Post
    What does the .bat file look like?
    I'd also suspect the batch file. Look for a PAUSE or CHOICE line in there, which are commonly used to wait for a keypress.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    16
    Doh.... when I run from the compiler I ge the pause, when I run the actual exe from either bat file or manually it works with no puase.....

    Thanks for putting up with me....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket closure periodic garbage collection
    By mynickmynick in forum Networking/Device Communication
    Replies: 1
    Last Post: 06-18-2010, 10:41 AM
  2. Replies: 1
    Last Post: 05-24-2010, 07:42 PM
  3. Having only one function run at higher priority
    By ulillillia in forum C Programming
    Replies: 35
    Last Post: 02-24-2008, 06:56 PM
  4. Newbie Help: Currency Converter
    By Ashfury in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 01:21 PM
  5. Making standalone APP run in background
    By hart in forum Windows Programming
    Replies: 3
    Last Post: 02-27-2005, 11:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21