Results 1 to 6 of 6

Thread: Program does nothing

  1. #1
    Join Date
    Aug 2016
    Location
    El Lago, Texas
    Beans
    475
    Distro
    Ubuntu Mate

    Program does nothing

    When I run this, nothing happens.

    Code:
    /* gcc numbers.c -o numbers  */
    #include <stdio.h>
     
    void print(int);
     
    int main()
    {
      int n;
     
      scanf("%d", &n);
     
      print(n);
     
      return 0;
    }
     
    void print(int n)
    {
      static int c = 1;
     
      if (c == n+1)
        return;
     
      printf("%d\n", c);
      c++;
      print(n);
    }
    Ubuntu Mate 18.04 Bionic
    Mate Desktop

  2. #2
    Join Date
    Apr 2012
    Beans
    7,257

    Re: Program does nothing

    How exactly are you running it? are you giving `scanf` any input to scan?

  3. #3
    Join Date
    Aug 2016
    Location
    El Lago, Texas
    Beans
    475
    Distro
    Ubuntu Mate

    Re: Program does nothing

    ./numbers

    Prog is supposed to print numbers.
    Ubuntu Mate 18.04 Bionic
    Mate Desktop

  4. #4
    Join Date
    Apr 2012
    Beans
    7,257

    Re: Program does nothing

    It only prints numbers after you give it an initial number `n`

    Code:
    $ ./numbers
    4 <ENTER>
    1
    2
    3
    4
    or
    Code:
    $ echo 4 | ./numbers
    1
    2
    3
    4
    Otherwise, it will just sit at

    Code:
      scanf("%d", &n);
    waiting for input

  5. #5
    Join Date
    Aug 2016
    Location
    El Lago, Texas
    Beans
    475
    Distro
    Ubuntu Mate

    Re: Program does nothing

    Thanks. I am looking for a C programming forum.
    Ubuntu Mate 18.04 Bionic
    Mate Desktop

  6. #6

    Re: Program does nothing

    Quote Originally Posted by raleigh3 View Post
    Thanks. I am looking for a C programming forum.

    You may want to visit cprogramming forum for advanced C programming topics in the future.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •