2009-11-25, 11:51 AM
"char first, second;"
That declares a variable named "first" which is assigned one byte. You need it to be a pointer.
"char* first, second;"
This makes "first" be a memory location for an array of characters (whether string or actual array - in C these are the same concept) somewhere else in memory. The way it was before was a reference to one byte of memory.
Also, because it's a pointer, you don't need the "&" in the scanf function call because your char* is already a pointer.
scanf("%s", first);
Also, instead of using "system("PAUSE");", try running your programs from the command prompt.
Finally, most C Programming courses allow functions to be global in scope, so you can move the function prototype for matchscore into the global section of the program.
" printf("The matchcount is %d\n", matchscore(first, second);" << missing a parenthesis there on the right?
That declares a variable named "first" which is assigned one byte. You need it to be a pointer.
"char* first, second;"
This makes "first" be a memory location for an array of characters (whether string or actual array - in C these are the same concept) somewhere else in memory. The way it was before was a reference to one byte of memory.
Also, because it's a pointer, you don't need the "&" in the scanf function call because your char* is already a pointer.
scanf("%s", first);
Also, instead of using "system("PAUSE");", try running your programs from the command prompt.
Finally, most C Programming courses allow functions to be global in scope, so you can move the function prototype for matchscore into the global section of the program.
" printf("The matchcount is %d\n", matchscore(first, second);" << missing a parenthesis there on the right?
