#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define ff fflush(stdin);

void main()
{
int r;
char str1[10], str2[10];
clrscr();

 printf("Enter password:\n");
 gets(str1);
  ff;
  printf("Re-enter password:\n");
   gets (str2);
    ff;

     r=strcmp(str1, str2);

         if(r==0)
             {
                printf("Enter");
               }
                else
                  {
                      printf("Exit");
                    }
getch();
}

I only got 2 errors with the upper program:

1) the main () cannot be void with my compiler so i put in int main()

2) The function Clrscr(); is invalid. If you wanted to use the clear screen function then you can type cls; instead of it.

Thats it and then the program works fine.

===========================
But it is not anything like a password program .

Try doing this .Program.

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>


int main()
{
int r;
char str2[10];
char str1[]="Password" ; // Replace the Password with the word "Password" Make sure the quoteS stay.

printf("Enter password:\n");
gets (str2);

r=strcmp(str1, str2);

if(r==0)
{
printf("Enter");
}
else
{
printf("Exit");
}
getch();

Hey Use the C++ Functions like Cin and cout with the Std namespace that will be easier.

I only got 2 errors with the upper program:

1) the main () cannot be void with my compiler so i put in int main()

2) The function Clrscr(); is invalid. If you wanted to use the clear screen function then you can type cls; instead of it.

Thats it and then the program works fine.

===========================
But it is not anything like a password program .

Try doing this .Program.

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>


int main()
{
int r;
char str2[10];
char str1[]="Password" ; // Replace the Password with the word "Password" Make sure the quoteS stay.

printf("Enter password:\n");
gets (str2);

r=strcmp(str1, str2);

if(r==0)
{
printf("Enter");
}
else
{
printf("Exit");
}
getch();

Hey Use the C++ Functions like Cin and cout with the Std namespace that will be easier.

This is what i get when i run the program that you posted, i have no idea how to fix it!

------ Build started: Project: password program, Configuration: Debug Win32 ------
Compiling...
project3.cpp
Linking...
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\password program\Debug\password program.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\My Documents\Visual Studio 2008\Projects\password program\password program\Debug\BuildLog.htm"
password program - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Hey Try compiling it with any other compiler or try this

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define ff fflush(stdin);

void main()
{
int r;
char str1[10], ;
clrscr();

printf("Enter password:\n");
gets(str1);
ff;
char str2[10]="password"; // TYPE THE PASSWORD HERE.
ff;

r=strcmp(str1, str2);

if(r==0)
{
printf("Enter");
}
else
{
printf("Exit");
}
getch();
}

Edited 6 Years Ago by Nick Evan: n/a

Hey Try compiling it with any other compiler or try this

#include<conio.h>
[..]
void main()
[...]
clrscr();
[...]
getch();

That won't work on any other compiler because it isn't standard C. It will probably only work on Turbo C, which is outdated.

At brianvolkmann :

You have a bracket-mismatch. You need one closing bracket after getch() (which you should replace with getchar() by the way) and you need to add a return 0; to the code, because main is an int function.

Edited 6 Years Ago by Nick Evan: n/a

Now I'm getting this error when i try to build the program.(microsoft visual is the only compiler i have available)

1>------ Build started: Project: password program, Configuration: Debug Win32 ------
1>Compiling...
1>password.cpp
1>z:\visual studio 2008\projects\password program\password program\password.cpp(8) : error C2447: '{' : missing function header (old-style formal list?)
1>z:\visual studio 2008\projects\password program\password program\password.cpp(36) : fatal error C1004: unexpected end-of-file found
1>Build log was saved at "file://\\cotrdata1\0066328$\Visual Studio 2008\Projects\password program\password program\Debug\BuildLog.htm"
1>password program - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define ff fflush(stdin);

int main();
{
int r;
char str1[10] ;
clrsr();

printf("Enter password:\n");
gets(str1);
ff;
char str2[10]="16bucks"; 
ff;

r=strcmp(str1, str2);

if(r==0)
{
printf("Enter");
}
else
{
printf("Exit");
}
{
getchar();
}
{
return 0;

}

Edited 6 Years Ago by Nick Evan: n/a

You still have a mismatch in brackets. Count how many opening and closing brackets you have. These two numbers should be equal. To avoid these kinds of problems, google for code-indention.

[edit] Here's a nice link about it [/edit]

Edited 6 Years Ago by Nick Evan: n/a

This article has been dead for over six months. Start a new discussion instead.