infinite loop

This is a discussion on infinite loop within the C Programming forums, part of the General Programming Boards category; hey guys i need a favor . i have written a code to read data from the RS232 port and ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Post infinite loop

    hey guys i need a favor . i have written a code to read data from the RS232 port and store that data in a file. The code is shown below

    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    #include<dos.h>
    unsigned int port1=0x3f8;
    unsigned char rfid[14];
    void main()
    {
    unsigned short c=0;
    int i=0;
    clrscr();
    outportb(port1+1,0x00u);
    outportb(port1+3,0x80u);
    outportb(port1+3,0x03u);
    outportb(port1+2,0xc7u);
    while(i<13)
    {
    c= inportb(port1+5);
    if(c&1)
    {
    rfid[i] = inportb(port1);
    i++;
    }
    }
    for(i=0;i<13;i++)
    {
    putchar(rfid[i]);
    }
    FILE *fp;
    int i=0;

    fp = fopen("tag.txt", "w");
    if (fp == NULL)
    {
    printf("Error trying to open the file\n");
    exit(0);
    }

    for (i=0; i<=13; i++)
    fprintf(fp, "%c", rfid[i]);

    getch();
    }
    i want this code to run infinte times that is the reading of the data from rs232 and saving should be done continuously. Please modify the code and help me out.
    Last edited by givemeway2004; 04-26-2009 at 09:47 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The best tip I can give you is to use code tags (click on "edit" button, then on "Go Advanced", and highlight your code. Then click on the # icon at the top of the edit window.)

    And learn a good indentation style!!

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    2
    i am sorry i am new to C . So i dint know abt the need for indentation.

  4. #4
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    493
    i am sorry i am new to C . So i dint know abt the need for indentation.
    So?There's nothing wrong in learning something new!!

    i want this code to run infinte times that is the reading of the data from rs232 and saving should be done continuously. Please modify the code and help me out.
    Wrap the code that you want to run continuously within a
    while(1) statement or a for ( ; ; )statement.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2009, 11:24 PM
  2. Cosine fucntion and infinite loop.
    By youareafever in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 03:45 AM
  3. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 12:09 PM
  4. Switch statement = infinite loop
    By Lucid003 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2005, 12:46 AM
  5. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 11:17 AM

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