I've added some comments to your code. Look for comments that start with "TC" (for "The Colonial" )
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void display();
int getinput();
int Subgetinput(char* p, int size);
bool Subgetinput2(char* p);
// TC: you've only got enough room for one character in this
// variable, but you want to be able to read in multiple characters,
// change this so that it can store more than one character.
char input; // YEAH SO ITS GLOBAL....SO WHAT
int main()
{
//char aWord[5];
while(true)
{
system("cls");
printf("\n\t\tMain Menu\n");
printf("F1 = Get Input\nF2 = Display input\nF3 = Exit\n");
char choice;
choice = getch();
if(choice == 0)
{
choice = getch();
if(choice == 61) break;
switch(choice)
{
case 59:
getinput();
break;
case 60:
display();
break;
default:
printf("try again.");
break;
}
}
else printf("Not a valid choice.");
}
// TC: main() returns an int
return EXIT_SUCCESS;
}
int getinput()
{
char arr1[15];
printf("enter Some characters: ");
int over;
over = Subgetinput(arr1, sizeof(arr1));
//input = ;
system("pause");
// TC: You need to return ... something!
return over;
}
// TC: This function needs to be looked at. you'll find that
// this is probably the biggest point of pain for you at the
// moment. Ask yourself what you're trying to do, and perhaps
// rethink/recode this bit.
int Subgetinput(char* p, int size)
{
char* end;
end = p + size - 1;
char in;
int overflow;
overflow = 0;
while(true)
{
in = fgetchar();
input = in;
if(in == 10) break;
if(p < end)
{
*p = in;
p++;
}
else overflow++;
}
*p = 0;
return overflow;
}
bool Subgetinput2(char* p)
{
char* beginning = p;
if(*p == 0) return false;
while(*p != 0)
{
if(*p ==' ')return false;
p++;
}
p = beginning;
while(*p != 0)
{
if(*p==*(p + 1))
{
if(*p == *(p + 2)) return false;
}
p++;
}
return true;
}
void display()
{
// TC: "input" is a char, and you're trying to output a string,
// either change this so that it outputs a single char (%c), or
// change the input variable to a c-style string.
printf("\t%s",input);
system("pause");
}
BTW, this code is very "C like" and not really "C++ like". Is this intentional?