Thread: Code not functioning properly

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    16

    Code not functioning properly

    I just started learning C, so please bear with my if my code is not all that great! So I am basically trying to print out "Start Typing >" utilizing lc4_puts(). Then I am trying to fall into a loop where it waits for me to type a character and then prints that character to the console. The program terminates when it encounters a line feed character char '/n'. My code is compiling, but not giving the desired result. "Start Typing >" prints to the screen, but I cannot type after that.

    Code:
    #include "os_trap_wrappers.h"
    
    // set the size of the character array input
    #define STRING_SIZE 100 
    
    
    int main(void)
    {
    	char c, input[STRING_SIZE];
    	int i;
    
    
    lc4_puts("Start Typing >");
    for (i = 0; (c = lc4_getc()) != '\n'; ++i) {
    	input[i] = c;
    
    
    
    
    }
    
    
    input[i] = '\0';
    lc4_putc(input[i]);
    return 0;
    }
    and this is my os wrapper code
    Code:
     char lc4_getc();void lc4_putc(char c);
    void lc4_puts(char *str); 
    void lc4_draw_box(int x, int y, int size, int *colors);
    any help would be greatly appreciated!

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    How are all these "lc4_*" functions implemented( lc4_getc in particular )?
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    In addition to what GReaper asked, note this:

    Code:
    input[i] = '\0';
    lc4_putc(input[i]);
    You're setting the last position of "input" to '\0' which is okay, but then you're only trying to print a single character - specifically, the '\0' you just put in that location. If you're intending to print out the entire string entered, this is not the way to do it.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    The ASCII nul ('\0') will not be visible on most displays!

    Code:
    input[i] = '\0';
    lc4_putc(input[i]);
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    16
    The macros getc() and putc() are used to read characters from the keyboard and to print characters on the screen, respectively.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    16
    thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-15-2012, 01:55 AM
  2. Exponent calculator not functioning properly....
    By working_with_c in forum C Programming
    Replies: 6
    Last Post: 09-29-2011, 10:50 AM
  3. max number program not functioning properly
    By MaaaTtY in forum C++ Programming
    Replies: 5
    Last Post: 03-02-2009, 11:53 AM
  4. how to properly comment on c code
    By agentsmith in forum C Programming
    Replies: 15
    Last Post: 01-30-2008, 01:13 PM
  5. if / else if / else statement not functioning properly
    By Beowolf in forum C Programming
    Replies: 8
    Last Post: 09-12-2007, 02:09 AM

Tags for this Thread