#include "stdio.h"
int main()
{

    //FILE *fp;
    char get[20] ;
    char password[15];
    int choice;

    choice:
    printf("\nSELETCT: 1.Login  2.Password change 0.Exit \n");
    scanf("%d", &choice);
    if(choice == 1)
    {
        FILE *fp;
        fp = fopen("PASS.txt","r");
        fgets(password,15,fp);
        printf("your current password is %s\n", password);
        printf("Enter password: ");
        scanf("%s",get);

        if( !strcmp(get, password) )
        {
            printf("\n%s\n", "Logged on succesfully!");
            goto choice;


        }

        else
        {
            printf("\n%s\n", "Incorrect login!");
            goto choice;
        }
    }
    else if(choice == 2)
    {        FILE *ft,*oldfl;
         char newpass[15];
         char cmp[15];
         printf("enter the old password:");
         scanf("%s",get);
         oldfl = fopen("PASS.txt","r");

         fgets(cmp,15,oldfl);
         if(!strcmp(get,cmp))
         {
            ft = fopen("PASS.txt","w");
            printf("\nenter the new password:" );
            scanf("%s",get);
            fputs(get,ft);
            fclose(ft);
            printf("\n Password Changed Successfully\n");
            goto choice;
         }
         else
         {
            printf("\nyou entered old password is wrong\n");
            goto choice;
         }

    }
} 

Someone help me out!

Dani AI

Generated

Turbo C often lets through nonstandard or unsafe habits that modern GCC toolchains will warn about or treat as undefined behavior. Common real causes when a program "works in Turbo C but not with gcc" are: missing function prototypes (which can silently break calls on modern ABIs), unhandled file/open errors, leftover newline or CR/LF characters from fgets, and unsafe input that overflows buffers. Fixing those systematically will make the program portable and reliable.

Quick checklist to apply here:

  • Compile with warnings enabled (for example gcc -Wall -Wextra -std=c11) and fix every warning.
  • Use the correct headers and include style (<stdio.h>, <string.h>). Missing prototypes for functions such as string helpers can cause undefined behavior on some systems.
  • Always check fopen and fgets return values and fclose files.
  • Be consistent with buffer sizes and leave space for the terminating NUL byte. Use width specifiers in scanf to avoid overflow.
  • Remove trailing newline/CR when reading a password from a file before comparing (files created on Windows can carry \r\n).

Two small, safe patterns to use:

/* strip trailing CR and LF after fgets */
password[strcspn(password, "\r\n")] = '\0';
/* check file open */
fp = fopen("PASS.txt", "r");
if (!fp) { perror("fopen PASS.txt"); /* handle error */ }

Also note: Turbo C sometimes uses nonstandard headers/functions (conio.h, gotoxy, etc.) that aren't on modern toolchains; avoid them. 's point about headers and avoiding goto is on target—replace the control flow with a simple loop/switch and handle all error returns. 's hint about platform-specific libraries is relevant too: confirm no Turbo-specific functions are relied upon. Finally, store real passwords hashed rather than in plain text if this code will ever be used beyond a learning exercise.

Recommended Answers

All 2 Replies

include the header string.h for string functions like strcmp

as a sidenote I'd suggest that you avoid using goto, instead you could use simpler methods like a switch condition

Did you used microsoft windows' function \ libs?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.