The first thing is to properly indent your code so it's readable, and so people will actually want to help you. Like so:
Code:
int main(void)
{
char szKey[] = "My Full Name";
char szInput[80];
void clrscr();
char szKey[] = "My Full Name";
char szInput[80];
do
{
printf("Enter my name: ");
gets(szInput);
}
while (strcmp (szKey,szInput) != 0);
system("CLS");
printf("Good");
getch();
}
Second, make sure you are using the actual code that produces the problem. The code you posted does not produce a double prompt. It does not produce anything because it doesn't compile.
Which brings me to my third point: make sure the code compiles with no errors or warnings at the highest warning level:
Code:
$ make foo
gcc -Wall -Wunreachable-code -ggdb3 -std=c99 -pedantic -lm -lpthread foo.c -o foo
foo.c: In function ‘main’:
foo.c:8: error: redefinition of ‘szKey’
foo.c:3: note: previous definition of ‘szKey’ was here
foo.c:9: error: redeclaration of ‘szInput’ with no linkage
foo.c:4: note: previous declaration of ‘szInput’ was here
foo.c:13: warning: implicit declaration of function ‘printf’
foo.c:13: warning: incompatible implicit declaration of built-in function ‘printf’
foo.c:14: warning: implicit declaration of function ‘gets’
foo.c:17: warning: implicit declaration of function ‘strcmp’
foo.c:18: warning: implicit declaration of function ‘system’
foo.c:19: warning: incompatible implicit declaration of built-in function ‘printf’
foo.c:20: warning: implicit declaration of function ‘getch’
make: *** [foo] Error 1
Lines 8,9: Why did you declare those variables a second time? Just once is enough.
Line 13,14,19: Using these functions requires you to #include <stdio.h>
Line 17: Using the strcmp() function requires you to #include <string.h>
Line 18: Using the system() function requires you to #include <stdlib.h>
Line 20: Don't use getch(). Use getchar() instead. It's nearly identical, and is a standard function, so everybody can use it.
Not listed, but still needs fixing:
Line 6: You don't use the clrscr() function anywhere, so remove this line. It does absolutely nothing.
Fixing all of that, and trying again:
Code:
$ make foo
gcc -Wall -Wunreachable-code -ggdb3 -std=c99 -pedantic -lm -lpthread foo.c -o foo
/tmp/ccRC1I9v.o: In function `main':
/home/tyco/sandbox/cprogramming/foo.c:13: warning: the `gets' function is dangerous and should not be used.
Ahh, yes, the gets() function. It is dangerous, I don't recommend using it. Use fgets instead (note, you will have to remove the new line). Read these links: FAQ > Why gets() is bad / Buffer Overflows - Cprogramming.com and FAQ > Get a line of text from the user/keyboard (C) - Cprogramming.com.