Find the answer to your Linux question:
Results 1 to 4 of 4
I'm a C++ and Java programmer and I'm learning C currently from an ebook. I just switch to Ubuntu from Windows. I used Ubuntu a little but never programmed in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    7

    Programmer needs help programming in Ubuntu!


    I'm a C++ and Java programmer and I'm learning C currently from an ebook. I just switch to Ubuntu from Windows. I used Ubuntu a little but never programmed in Ubuntu before. I am doing an exercise in the book and what it does is gets the keyboard input and then prints it on the screen. It uses a while loop to get the characters until it reaches that EOF but when I run it in the terminal, I can't end the program. Its probably easy to fix but I'm not sure what to do.

    He is the code

    Code:
    #include <stdio.h>
    
    /* copy input to output; 1st version */
    main()
    {
    	int c;
    	int quit;
    
    	quit = 0;
    	
    	while((c = getchar()) != EOF)
    	{
    		
    		putchar(c);
    		
    	}
    }

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    476
    works fine for me

    2 comments:
    1. do you need the int quit?
    2. end the program by giving an EOF=ctrl-d
    the sun is new every day (heraclitus)

  3. #3
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    ctrl-d is the EOF in a terminal.

  4. #4
    Just Joined!
    Join Date
    Apr 2010
    Posts
    7
    Ok I didn't know EOF is ctrl-d. Also the quit was in there because I was testing something. Thanks!!!

Posting Permissions

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