troubleshooting Question

using getchar() to input 2-digit numbers

Avatar of frostyourself
frostyourself asked on
Programming Languages-OtherC
5 Comments1 Solution1529 ViewsLast Modified:
I want to have user input for the hours, minutes, and seconds that a timer starts at. I need to use getchar() instead of scanf because of a limited memory. I called the getchar() function twice for each time unit, but the code doesn't work for inputting 2-digit numbers.

alt_u8 seconds = 0;
alt_u8 minutes = 0;
alt_u8 hours = 0;

char sHours[3];
char sMinutes[3];
char sSeconds[3];

alt_printf("enter hour:\n");
      sHours[0] = getchar();
      sHours[1] = getchar();

      alt_printf("enter minutes:\n");
          sMinutes[0] = getchar();
            sMinutes[1] = getchar();

            alt_printf("enter seconds:\n");
                      sSeconds[0] = getchar();
                        sSeconds[1] = getchar();

                        hours = atoi(sHours);
                        minutes = atoi(sMinutes);
                        seconds = atoi(sSeconds);

update_monitor(hours, minutes, seconds); //prints time
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros