Ошибка, возвращаемое значение 3221225477 при запуске c ошибка выполнения кода - PullRequest
1 голос
/ 18 июня 2020

Я пытался написать программу, которая будет иметь массив сотрудников, и, читая данные из ввода, делаю некоторые вещи, такие как добавление еще одного нового сотрудника, удаление одного, отображение списка всех сотрудников или выход из программы, но пока я имел дело со всеми ошибками в моем коде и смог наконец его скомпилировать, у меня было это возвращаемое значение, и я не знаю, что с ним делать.

#include<stdio.h>
#include<string.h>
using namespace std;
struct employee{
     int id;
    char* name;
};
int main(){
    char* input;
    employee person[30];
    int employee_count=0;
    bool command=false;
    while(input !="exit"){
        fgets(input, 100, stdin); 
        char* temp;
        strncpy(input, temp, 3);
        if(temp=="add"){
            char* name;
            for(int x=0; x<100; x+=1){
                temp[x]='\0';
            }
            int i=4;
            for(; input[i]!=' '; i+=1){ 
                const char* tmp = &input[i];
                temp=strcat((char*)temp,tmp);
            }
            person[employee_count+1].name=temp;
            name=temp;
            for(int x=0; x<100; x+=1){
                temp[x]='\0';
            }
            for(; i<strlen(input); i+=1){
                const char* tmp = &input[i];
                temp=strcat((char*)temp,tmp);
            }
            printf("%s added.", name);
            command=true;
            employee_count+=1;
        }
        strncpy(input, temp, 3);
        if(temp=="del"){
            for(int x=0; x<100; x+=1){
                temp[x]='\0';
            }
            for(int i=4; input[i]!=' '; i+=1){
                const char* tmp = &input[i];
                temp=strcat((char*)temp,tmp);
            }
            int i=0, found=0;
            for(; i<employee_count; i+=1){
                if(person[i].id==*((int*)(&temp))){
                    found=1;
                    break;
                }
                temp=person[i].name;
                if(found==1){
                    for(int j=i; j<employee_count; j+=1){
                        person[j]=person[j+1];
                    }
                    printf("%s deleted.", temp);
                }
                else{
                    printf("not found.");
                }
            }
            command=true;
            employee_count-=1;
        }
        strncpy(input, temp, 4);
        if(temp=="list"){
            for(int i=0; i<employee_count; i+=1){
                printf("%d %s", person[i].id, person[i].name);
            }
            command=true;

        }
        else if(command==false){
            printf("invalid command.\n");
        }
    }   
    return 0;
}
...