Thread: stop an executing C program and finish executing additonal line of code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Doesn't it come with some documentation? What are you using to read from it? Post a very simple bit of code illustrating your attempt:
    Code:
    #include<stdio.h>
    #include "whateveryourboardrequires.h"
    
    int main( void )
    {
       //simple stuff needed for a single read, no unnecessary crap
    
        for(;;)
        {
            //an illustration of your read function call such as:
            read( foo, bar );
        }
        return 0;
    }
    OS, compiler, board make and model, etc would be helpful also.


    Quzah.
    Hope is the first step on the road to disappointment.

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    14
    quzah, thanks for the reply. I think I didn't explain the situation correctly. Your code is basically what I'm doing, except that the for loop is a while(1) loop. It goes on forever, because I have no way of knowing how long i'm going to acquire the data.

    Right now to stop my program, I just hit ctrl+c. I would like a way of stopping from a user input and also execute some chunk of code (in a function possibly?) before ending the program.

    I was thinking of using the wait time between acquisition to listen for some key. But I don't know if that will possibly work and how to start.

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by darkwalk
    quzah, thanks for the reply. I think I didn't explain the situation correctly. Your code is basically what I'm doing, except that the for loop is a while(1) loop. It goes on forever, because I have no way of knowing how long i'm going to acquire the data.

    Right now to stop my program, I just hit ctrl+c. I would like a way of stopping from a user input and also execute some chunk of code (in a function possibly?) before ending the program.

    I was thinking of using the wait time between acquisition to listen for some key. But I don't know if that will possibly work and how to start.
    You say you are writing a master thesis!! Not in a computing related subject one would hope!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM