c程序中的用户认证

问题描述 投票:3回答:1

我有两个'c'程序,第一个是学生管理系统程序,第二个是登录程序,我在合并两个程序时遇到麻烦我想用我的“登录程序”认证我的“学生管理程序”他们不是一起跑,给出很多错误所以请帮助我:(。

学生管理系统课程

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<string.h>
struct std
{
   char name[50];
   char city[50];
   char sub[50];
   int marks;
   long int roll;

   struct std *link;
}*start=NULL,*tmp,*ptr;
void main()
{
   int ch;
   clrscr();
   while(ch!=3)
   {
      printf("\nEnter your choice");
      printf("\n****MENU****");
      printf("\n1.create");
      printf("\n2.display");
      printf("\n3.exit\n");
      scanf("%d",&ch);
      switch (ch)
      {
         case 1:
            record();
            break;

         case 2:
            display();
            break;

         case 3:
            exit();
            break;

         default:
            printf("wrong choice");
      }
   }
   getch();
}

record()
{
   char nam[50],cit[50],subj[30];
   tmp=(struct std*)malloc(sizeof(struct std));
   printf("\nEnter Student name:" );
   fflush(stdin);
   gets(nam);
   strcpy(tmp->name, nam);
   printf("\nEnter subject of student: ");
   fflush(stdin);
   gets(subj);
   strcpy(tmp->sub, subj);
   printf("\nEnter City of student: ");
   fflush(stdin);
   gets(cit);
   strcpy(tmp->city, cit);
   printf("\nEnter Marks of Student: ");
   scanf("%d",&(tmp->marks));
   printf("\nEnter Roll Number of Student: ");
   scanf("%ld", &(tmp->roll));
   fflush(stdin);
   tmp->link=NULL;
   if(start==NULL)
   {
      start=tmp;
   }
   else
   {
      ptr=start;
      while(ptr!=NULL)
      {
         ptr=ptr->link;
         ptr->link=tmp;
      }}
}

display()
{
   if(start==NULL)
   {
      printf("list empty\n");
   }
   else
   {
      ptr=start;
      while(ptr!=NULL)
      {
         printf("Name of the student: ");
         puts(tmp->name);
         printf("subject of Student: ");
         puts(tmp->sub);
         printf("city of student: ") ;
         puts(tmp->city);
         printf("marks of student: %d\nRoll No of student: %ld",(tmp->marks),(tmp->roll));
         ptr=ptr->link;
      }
   }
}

登录程序

#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
   char userid[]="uim",password[]="123",p[15],u[15];
   int n=1,a,b;
   printf("\nEnter USER ID and PASSWORD below (You have only three chances to enter)");
   getch();
   while(n<=3)
   {
      clrscr();
      printf("\nUSER ID: ");
      scanf("%s",u);
      printf("\nPASSWORD: ");
      scanf("%s",p);
      a=strcmp(u,userid);
      b=strcmp(p,password);
      if(a==0&&b==0)
      {
         printf("\nYou have logged in successfully.");
         break;
      }
      else
      {
         printf("\nWrong PASSWORD and/or USER ID. Now you have % d more chance/s.",3-n);
      }
      getch();
      n++;
   }
   if(n==4)
      printf("\nYou can't log in.");
   getch();
}
c login authentication
1个回答
0
投票

首先使用system()函数在代码中运行登录代码并收集返回值,如果有错误终止,则可以继续读取数据。

另一种方法是使用一个函数进行登录并从程序的主程序调用

© www.soinside.com 2019 - 2024. All rights reserved.