Process Terminated with status -1073741510

This is a discussion on Process Terminated with status -1073741510 within the C Programming forums, part of the General Programming Boards category; My code is: Code: #include "header.h" int main(){ int PAttack, PDefense; int EAttack, EDefense; int PDmgDealt, EDmgDealt; int PHP = ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    3

    Process Terminated with status -1073741510

    My code is:

    Code:
    #include "header.h"
    
    int main(){
        int PAttack, PDefense;
        int EAttack, EDefense;
        int PDmgDealt, EDmgDealt;
        int PHP = 100, Php;
        int EHP = 100, Ehp;
        char input[4+1];
        int choice;
        Ehp = EHP - PDmgDealt;
        Php = PHP - EDmgDealt;
    
    
        srand(time(NULL));
    
    do{
        PAttack = rand() % 50 + 1;
        EDefense = rand() % 50 + 1;
        EAttack = rand() % 50 + 1;
        PDefense = rand() % 50 + 1;
    
        printf("1. Attack\n");
        printf("2. Skill\n");
        printf("3. Item\n");
        printf("4. Run\n");
        fgets(input, 4, stdin);
        choice = atoi(input);
    
        attacking( choice, PAttack, EDefense, PDmgDealt, EHP, Ehp, EAttack, PDefense, EDmgDealt, PHP, Php);
    } while(Ehp != 0);
        return 0;
    }
    Code:
    #include "header.h"
    
    
    void PDmgChk(int PAttack,int EDefense,int PDmgDealt, int EHP, int Ehp){
    
    
            PDmgDealt = PAttack - EDefense;
    
    
        // If Player's Attack is equal to the Enemy's Defense then do nothing
        if(PAttack == EDefense){
            PDmgDealt = 0;
            printf("You've dealt no damage");
            printf("The enemy now has %d", Ehp);
            printf(" HP\n");
        }
    
        // If Player's Attack is greater then the Enemy's Defense, deal damge
        else if(PAttack > EDefense){
            printf("You've dealt ");
            printf("%d", PDmgDealt);
            printf(" damage\n");
            printf("The enemy now has %d", Ehp);
            printf(" HP\n");
    }
    
    
    // If Player's Attack is less then the Enemy's defense do nothing.
        else if(PAttack < EDefense){
            PDmgDealt = 0;
            printf("You've dealt no damage! \n");
            printf("The enemy now has %d", Ehp);
            printf(" HP\n");
        }
    // Shows Player's Attack and Enemy's Defense REMOVE BEFORE FININSHING.
        printf("%d \n", PAttack);
        printf("%d\n" , EDefense);
        }
    
    void EDmgChk(int EAttack, int PDefense, int EDmgDealt, int PHP, int Php){
            EDmgDealt = EAttack - PDefense;
            // If Enemy's Attack is equal to Player's Defense, do nothing.
        if(EAttack == PDefense){
            EDmgDealt = 0;
            printf("The Enemy dealt no damage to you\n");
            printf("You now have %d", Php);
            printf(" HP\n");
    }
    
    // If Enemy's Attack is greater than the Player's Defense, deal damage.
        if(EAttack > PDefense){
            printf("The Enemy dealt ");
            printf("%d", EDmgDealt);
            printf(" damage to you.\n");
            printf("You now have %d", Php);
            printf(" HP\n");
    }
    
    // If Enemy's Attack is less than the Player's Defense, do nothing.
        if(EAttack < PDefense){
            EDmgDealt = 0;
            printf("The Enemy dealt no damage to you.\n");
            printf("You now have %d", Php);
            printf(" HP\n");
        }
    
        printf("%d\n", EAttack);
        printf("%d\n", PDefense);
    }

    Code:
    #include "header.h"
    
    void attacking(int choice, int PAttack, int EDefense, int PDmgDealt, int EHP, int Ehp, int EAttack, int PDefense, int EDmgDealt, int PHP, int Php)
    {
        switch (choice){
        case 1:
                Attack(PAttack, EDefense, PDmgDealt, EHP, Ehp);
                EDmgChk(EAttack, PDefense, EDmgDealt, PHP, Php);
                break;
        case 2:
                Skill();
                EDmgChk(EAttack, PDefense, EDmgDealt, PHP, Php);
                break;
        case 3:
                Item();
                EDmgChk(EAttack, PDefense, EDmgDealt, PHP, Php);
                break;
        case 4:
                Run();
                break;
    }
    
    }
    
    void Attack(PAttack, EDefense, PDmgDealt, EHP, Ehp){
        PDmgChk(PAttack, EDefense, PDmgDealt, EHP, Ehp);
    }
    
    void Skill(){
    
    }
    
    void Item(){
    
    }
    
    void Run(){
    
    }


    (Yes, I'm a newbie to coding, and sorry for the messy code.)

    But anyways everything else works here, but receiving -1073741510 upon termination of the program.
    Last edited by Varethien; 08-09-2011 at 04:10 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    You want us to guess, based on not knowing anything about how your attacking() function works?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    3
    I updated with all files.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    PDmgDealt = PAttack - EDefense;
    if(PAttack == EDefense)
    {
        PDmgDealt = 0;
    }
    Why bother with the first line, if you are going to do the next set of checks?
    Code:
        // If Player's Attack is equal to the Enemy's Defense then do nothing
        if(PAttack == EDefense){
            printf("You've dealt no damage");
            printf("The enemy now has %d", Ehp);
            printf(" HP\n");
        }
    Then you do the same check again.
    Code:
        int PHP = 100, Php;
        int EHP = 100, Ehp;
    Those are used uninitialized. Your compiler should be warning about that.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    3
    I've initiated them ( Or I think I have. . .), but now the HP values are messed up.

    http://i51.tinypic.com/517w5e.png

    They're supposed to be 100, but they get changed after using one of the cases.

    Also still getting the Process Terminated with Status -1073741510.

    Also updated original post with the new code.
    Last edited by Varethien; 08-09-2011 at 04:11 AM.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Varethien View Post
    I've initiated them ( Or I think I have. . .)
    I see ... two functions later.

    Anyway, you can't update all those variables you are passing to your functions, and have them persist on any function that has called it. You need pointers for that.

    "What?"
    Code:
    #include<stdio.h>
    void bar( int x )
    {
        --x;
        printf( "bar\'s x is %d\n", x );
    }
    void foo( int x )
    {
        printf( "foo\'s x is %d\n", x );
        bar( x )
        printf( "foo\'s x is %d\n", x );
        --x;
    }
    int main( void )
    {
        int x = 4;
        printf( "main\'s x is %d\n", x );
        foo( x );
        printf( "main\'s x is %d\n", x );
        return 0;
    }

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Process terminated with status -1073741819
    By smithx in forum C Programming
    Replies: 5
    Last Post: 11-01-2010, 11:13 PM
  2. I don't get what cause the following while loop to terminated
    By Overworked_PhD in forum C Programming
    Replies: 3
    Last Post: 08-11-2009, 09:30 PM
  3. Replies: 1
    Last Post: 02-04-2009, 05:54 AM
  4. Child process status
    By paraglidersd in forum C Programming
    Replies: 8
    Last Post: 07-24-2008, 10:51 AM
  5. get the status of the child process
    By mystic-d in forum C Programming
    Replies: 9
    Last Post: 11-17-2007, 03:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21