C program not executing more than once

Discussion in 'C Programming' started by satya123, Mar 24, 2011.

  1. satya123

    satya123

    Joined:
    Jul 6, 2010
    Messages:
    6
    Hi all,

    I have written the following code for displaying the characters which are more than 20 characters

    /* Write a program to print all input lines that
    are longer than 20 characters */

    #include <stdio.h>
    int main()
    {
    int c;
    unsigned int nw=0;
    char array[100];

    while((c = getchar()) != EOF)
    {
    array[nw] = c;
    nw++;

    if(c == '\n')
    {
    if(nw >= 20)
    {
    array[nw] = '\0';
    printf("%s",array);
    nw=0;
    }
    else
    {
    printf("Sorry less than 20 Char\n");
    nw=0;
    }
    }
    }
    return 0;
    }

    i have compiled the above program in command prompt using the command tcc test.c the compiler then generates test.exe file. For the first time if i type test it gives me the expected output, but if i run the program again by typing test, the program does not run. i need to recompile the program again to execute the program. could somebody help me on this?

    Thanks
    satya
     
    satya123, Mar 24, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Todd Krein

    Can't run BLT program more than once?

    Todd Krein, Apr 28, 2005, in forum: Python
    Replies:
    0
    Views:
    354
    Todd Krein
    Apr 28, 2005
  2. Christopher Subich
    Replies:
    4
    Views:
    643
    Christopher Subich
    Jun 12, 2005
  3. Gancy
    Replies:
    4
    Views:
    241
    Rasto Levrinc
    Feb 3, 2005
  4. Steven D'Aprano
    Replies:
    0
    Views:
    143
    Steven D'Aprano
    Dec 23, 2013
  5. dec135@msn.com
    Replies:
    3
    Views:
    116
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page