Hello, :)
I have chosen to go with getch() for my keyboard input.
However, when I went to experiment with it, I got some unexpected results. The 'Y' in 'Your word was ' is missing in the command prompt when I run this program after I compile using gcc, and when I compile it using Dev-C++ 4, my program doesn't even show the last 2 output lines which are intended to show you what the values are in the variables.
I get no errors or warnings when I compile in either one, and I have quadruple checked my logic, and even went back to my C book from college, and my syntax is identical to his.
Can you try this code on your compiler to see what happens? Any suggestions?
Thanks alot, :lol:
Diode
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <process.h>
void clear(void);
void settext(void);
// BEGINNING OF PROGRAM
int main() // starts the program
{
char str[20]; // declares char array 'str'
int num = 0; // declares the integer 'num'
int length = 0; // declares the integer 'length'
clear(); // clears the screen
printf("Enter a word: "); // instructs you to enter a word
do // starts loop for input
{
str[num] = getch(); // puts a char into 'str'
printf("%c", str[num]); // echoes char to screen
if (str[num] >= 'A') // this whole 'IF' block
{ // checks to see if the
if (str[num] <= 'Z') // entered character is
{ // uppercase, and if so,
str[num] = str[num] - 'A' + 'a'; // converts it to
} // lowercase
} //
num++; // increments 'num' by 1
} while(str[num-1] != 0x0D); // loops until ENTER is hit
length = num - 1; // assigns the value of 'num'
// minus 1 (the length of 'str')
// to 'length'
printf("\n\nYour word was %s \n\n", str); // outputs 'str' to screen
printf("\nIt is %d characters long", length);
// outputs 'str' and its
// length to the screen
settext(); // holds output until
// a key is pressed
clear(); // clears the screen
return 0; // quits program with
// condition zero
}
// END OF PROGRAM
// BEGINNING OF FUNCTIONS
void clear(void)
{
system("cls");
}
///////////////////////////////////
void settext(void)
{
char text;
text = getch();
}