Compiling the following problem with visual studio 2000 gives the errors:
temp.obj : error LNK2001: unresolved external symbol "void __cdecl ungetch(int)" (?ungetch@@YAXH@Z)
temp.obj : error LNK2001: unresolved external symbol "int __cdecl getch(void)" (?getch@@YAHXZ)
Debug/temp.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
The code is taken from Dennis Ritchie's "C Programming Language" 's page 97 (2nd Edition).
#include<stdio.h>
#include<ctype.h>
int getch(void);
void ungetch(int);
int getint(int *pn)
{
int c, sign;
while (isspace(c=getch()));
if(!isdigit(c) && c != EOF && c != '+' && c != '-')
{
ungetch(c);
return 0;
}
sign = ( c == '-') ? -1 : 1;
if( c== '+' || c == '-')
c = getch();
for( *pn = 0; isdigit(c); c = getch())
*pn = 10 * *pn + (c - '0');
*pn *= sign;
if (c != EOF) ungetch(c);
return c;
}
int main()
{
int *p;
p = new int[10];
p[0] = 4;
p[1] = 2;
p[2] = 6;
p[3] = 8;
p[4] = 2;
p[5] = 1;
p[6] = 7;
p[7] = 1;
p[8] = 2;
p[9] = 1;
int i = getint(p);
printf("The value is %d", i);
return 0;
}