| | |
Linking Error
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 21
Reputation:
Solved Threads: 2
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).
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).
C Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Feb 2008
Posts: 630
Reputation:
Solved Threads: 46
getch() is a c language thing:
http://www.daniweb.com/forums/thread11811.html
I think that book was wanting you to include conio.h, but as you will see if you are working in c++ you likely shouldn't be using that.
http://www.daniweb.com/forums/thread11811.html
I think that book was wanting you to include conio.h, but as you will see if you are working in c++ you likely shouldn't be using that.
main() is passing an array of ints to that function, but the function is using it like its a pointer to a single int.
>>The code is taken from Dennis Ritchie's "C Programming Language" 's page 97 (2nd Edition).
I doubt it -- he is a hell of a lot better programmer than that!
>>The code is taken from Dennis Ritchie's "C Programming Language" 's page 97 (2nd Edition).
I doubt it -- he is a hell of a lot better programmer than that!
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2009
Posts: 36
Reputation:
Solved Threads: 7
•
•
•
•
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).
C Syntax (Toggle Plain Text)
#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; }
2. You are mixing C++ with C, I think new opeartor is used with C++ but not with C.
![]() |
Similar Threads
- g++ - linking error - undefined reference to <func_name> (C++)
- I keep getting an unresolved linking error, need help (C++)
- Linking error in the compiler given by topcoder. Plz help me out guys. (C++)
- linking error (C++)
- Linking Error (C++)
Other Threads in the C Forum
- Previous Thread: need help
- Next Thread: Bison ! "start symbol 'grammar' does not derive any sentence" meaning?
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation testing threads unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






