返回值3221225477?

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

我对编码非常陌生,所以请对我轻松一点>>

这是我的代码

/* Open File*/
FILE *openFile(char filename[], char filetype[]);
/* Read Number Of Nurses */
int readNurses(void);
/* Title */
void title(void);
/* Login Screen*/
int loginScreen();
/* Checks if memory allocation was correct */
void mallocCheck(char **malloc1, char **malloc2);
/* Asks for login details */
int askLogin(void);
/* Retrieve Login Details */
void getDetails(char **properID, char **properPASS, int nurses);
/* Test Details Input To Details */
int testDetails(void);
/* Encryption Of Password */
void encryptPass(void);
/* Main Menu */
void mainMenu(void);
/* Encrypt Patient's Details */
void encrtpyPatient(void);
/* Enter Patients Details */
void enterPatients(void);
/* Create Patients File */
void createPatient(void);
/* Clear Screen Smooth */
void clearScreen(void); 

int main(void)
{
    int nurses;
    int correct;
    char enterID[ID_LENGTH];
    nurses = readNurses();
    correct = loginScreen(enterID, nurses);
    title();
    return 0;
}

void title(void)
{
    printf("\n\n\n            =================================");
    Sleep(SLEEP_TIME);
    printf("\n            =                               =");
    Sleep(SLEEP_TIME);
    printf("\n            =  Welcome to Action On Weight  =");
    Sleep(SLEEP_TIME);
    printf("\n            =                               =");
    Sleep(SLEEP_TIME);
    printf("\n            =================================");
    Sleep(SLEEP_TIME);
    printf("\n                    *****************");
    printf("\n               ******               ******");
    printf("\n           ****                           ****");
    printf("\n        ****                                 ***");
    printf("\n      ***                                       ***");
    printf("\n     **           ***               ***           **");
    printf("\n   **           *******           *******           **");
    printf("\n   **           *******           *******           **");
    Sleep(SLEEP_TIME);
    printf("\n   **           *******           *******           **");
    printf("\n   **             ***               ***             **");
    printf("\n   **                                               **");
    printf("\n   **      *                                 *      **");
    printf("\n   **     **                                 **     **");
    printf("\n   **  ***                                     ***  **");
    printf("\n   **     *                                  *      **");
    printf("\n   **      ***                           ***        **");
    Sleep(SLEEP_TIME);
    printf("\n   ***      ****                       ****       ***");
    printf("\n     **         ******             ******         **");
    printf("\n      ***            ***************            ***");
    printf("\n        ****                                 ****");
    printf("\n           ****                           ****");
    Sleep(SLEEP_TIME); 
    printf("\n               ******               ******");
    printf("\n                    *****************");
    Sleep(SLEEP_TIME);
    Sleep(SLEEP_TIME);
}


int readNurses(void)
{
    FILE *fin;
    int nurses;
    fin = openFile("Nurses.txt", "r");
    while(!feof(fin))
    {
        fscanf(fin, "%*s");
        nurses++;
    }
    fclose(fin);
    printf("%d", nurses);
    return nurses;
}

FILE *openFile(char filename[], char filetype[])
{
    FILE *ptr = fopen(filename, filetype);
    if(!ptr)
    {
        printf("\n\n\n        Error 1. File couldn't be opened.");
              (" Please contact us at [email protected]");
              exit(1);
    }
    return ptr;
}

int loginScreen(char enterID[], int nurses)
{
    int correctDetails;
    int loop;
    char *properID;
    char *properPASS;
    properID = (char*) malloc(ID_LENGTH * nurses * 60);
    properPASS = (char*) malloc(PASS_LENGTH * nurses *60);
    correctDetails = 0;
    mallocCheck(&properID, &properPASS);
    getDetails(&properID, &properPASS, nurses);
    loop = nurses - 1;
    printf("das");
    while(nurses > 0)
    {
        printf("%s : %s", &properID[nurses], &properPASS[nurses]);
        nurses--;
    }
    /* do
    {
        printf("\n\n\n              ================================");
        printf("\n              =                              =");
        printf("\n              =         Login Screen         =");
        printf("\n              =                              =");
        printf("\n              ================================");
    }while(correctDetails = 0); */
    while(loop > 0)
    {
        free(properID - loop);
        free(properPASS - loop);        
        loop--;
    }
    return correctDetails;
}

void mallocCheck(char **malloc1, char **malloc2)
{
    if(malloc1 == NULL ||malloc2 == NULL)
    {
        printf("\n\n\n        Error 2. Assignment of ");
        printf(" memory wasn't succcesful.");
        printf(" Please contact us at [email protected]");
        Sleep(SLEEP_TIME);
        Sleep(SLEEP_TIME);
        exit(0);
    }
}

void getDetails(char **properID, char **properPASS, int nurses)
{
    FILE *ptr;
    ptr = openFile("Nurses.txt", "r");
    while(!feof(ptr))
    {
        fscanf(ptr, "%[^.]%*c%s\n", 
        &properID[nurses], &properPASS[nurses]);
        nurses--;
    }
    fclose(ptr);
}

问题出在函数loginScreen()中,函数getDetails()得到运行,但是一旦完成3221225477,有人可以指出我为什么会这样吗?看来我正在正确分配内存和所有内容。我试图找出为什么会这样,但是我什么也找不到。

我对编码很陌生,所以请对我轻松一点这是我的代码/ *打开文件* / FILE * openFile(char filename [],char filetype []); / *读取护士人数* / int readNurses(void); / *标题* /无效...

c memory memory-management c99
1个回答
0
投票

3221225477是十六进制的0xC0000005,它是NTSTATUS代码STATUS_ACCESS_VIOLATION。您的程序以某种方式破坏了其工作内存。而是在Linux上编译程序;然后您可以在valgrind下运行它,并确切告知问题出在哪里。

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