Thread: *** process returned -1 ***

  1. #1
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9

    Cool *** process returned -1 ***

    has anyone run across this error before? *** process returned -1 ***

    I am writing this program for class and I am getting this error in the command screen but I have no compiler issues. It simply asks me to press a key and it exits the program. Can someone help me with this and let me know what I am doing wrong? Below is the code I have written so far.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    This line is an error:
    Code:
    printf("Power is %f watts.  Power is at Maximum level. \n");
    as your compiler says, "too few arguments for format".

    You are using R2 without it being initialized.

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9
    Ok, got that line corrected. What do you mean by R2 not being initialized? My compiler isn't telling me too few arguments for format. it tells me

    Building Maximum Power.
    Writing debug information
    Compacting CodeView information
    Done.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by bilbo67216 View Post
    Ok, got that line corrected. What do you mean by R2 not being initialized?
    When you first get to the line
    Code:
    while (R2 !=0)
    R2 has the value p98yupoqiwhefp98ahsffgp;9uq3wp48y5q23;rj, since no real value has been stored in that variable.

  5. #5
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9
    ok, so the statement R2 = 5000 is after the fact and needs to be before somewhere? What would you suggest?

  6. #6
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9
    Does anyone have any suggestions here? I have tried changing up that while statement many ways and still get the "process returned -1" error. This is getting really frustrating.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Quote Originally Posted by tabstop View Post
    When you first get to the line
    Code:
    while (R2 !=0)
    R2 has the value p98yupoqiwhefp98ahsffgp;9uq3wp48y5q23;rj, since no real value has been stored in that variable.

    Aren't all global variables initialised to 0 by the compiler?

    (Note that if the code has been edited since you wrote that, then just ignore this).

    In your current code, you have a while loop with the condition as "R2 != 0", this won't run at all (because of what I mentioned above, I'm fairly sure of it anyway).

    Apply the changes suggested so far and re-upload the code (or just post it here in code tags, it's not terribly long).

    Also, your indentation is pretty horrible. It will make the code easier to read for yourself and everyone with good indentation. You do have some indentation, it's just not consistent enough.

  8. #8
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9

    changes

    Code:
    #include <stdio.h>
    
    #define R1 100
    
    int R2;
    int RL;
    double V;
    double VR2;
    double VR1;
    double VRL;
    double PR2;
    double PRL;
    double I;
    
    int
    main (void){
    
    int valid = 0;
    
    while (valid == 0) { /*page 195*/
    	printf("Enter Power Supply Voltage Setting on the Programmable Power Supply in 0.1 volt increments (1-15)>\n");
     	scanf("%3lf", &V);
    	if (V > 15){
    		printf("\n Invalid value.  The value must be 15 or less. \n");
    		valid = 0;}
    	else if (V < 1){
    		printf("\n Invalid value.  The value must be one or greater. \n");
    		valid = 0; }
    	else 
    		valid = 1;
    
    }
    
    int result = 0;
    
    while (result == 0) {		
    	printf("Enter Total Load Resistance in one ohm increments (100-5000)>\n");
    	scanf("%d", &RL);
    	if (RL > 5000 ){
    		printf("\n Invalid value.  The value must be 5000 or less. \n");
    		result = 0;}
    	else if (RL < 100){
    		printf("\n Invalid value.  The value must be 100 or greater. \n");  
    		result = 0;}
    	else
    		result = 1;
    
    }
    int R2 = 5000;
    
    while (R2 != 0){	
    		R2 = 5000;
    	
    /*total current*/
    I = V / (R2 + R1 + RL);
    printf("Total current is %f amps. \n", I);
    
    /*Voltage drop across R2*/
    VR2 = (I * R2);
    printf("Voltage of R2 is %f VDC. \n", VR2);
    
    /*Voltage drop across R1*/
    VR1 = (I * R1);
    printf("voltage of R1 is %f VDC. \n", VR1);
    
    /*Voltage drop across load*/
    VRL = (I * RL);
    printf("Voltage of load is %f VDC. \n", VRL);
    
    /*Power drop across R2*/
    PR2 = I * VR2;
    printf("Power across R2 is %f watts.  \n", PR2);
    
     /*Power drop across load*/
    PRL = I * VRL;
    		if (R2 != 0){
    			printf("Power is %f watts.  \n", PRL);
    			R2 = R2 - 1;}
    		else
    			printf("Power is %f watts.  Power is at Maximum level. \n", PRL);
    }
    return(0);}
    I guess I am not understanding what changes need to be made. I need the loop to execute until R2 = 0. At that point I want the loop to end and the final statement of max power stated. Sorry, but three months ago I didn't even know what C programming was. You stated to make the changes stated but I guess I am not seeing what changes need to be made. I can be pretty dense sometimes while the obvious is biting my leg.

  9. #9
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9
    Code:
    int R2 = 5000;
    
    while (R2 > 0){
    here is a change I made that still results in that error. It seems everything I do won't fix it.

  10. #10
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    First thing's first:

    Code:
    #include <stdio.h>
    
    #define R1 100
    
    int R2;
    int RL;
    double V;
    double VR2;
    double VR1;
    double VRL;
    double PR2;
    double PRL;
    double I;
    
    int main (void)
    {
            int valid = 0;
    
            while (valid == 0)  /*page 195*/
            {
    	        printf("Enter Power Supply Voltage Setting on the Programmable Power Supply in 0.1 volt increments (1-15)>\n");
     	        scanf("%3lf", &V);
    	        if (V > 15)
                    {
    		        printf("\n Invalid value.  The value must be 15 or less. \n");
    		        valid = 0;
                    }
    	        else if (V < 1)
                    {
    		        printf("\n Invalid value.  The value must be one or greater. \n");
    		        valid = 0;
                    }
    	        else 
    		        valid = 1;
            }
    
            int result = 0;
    
            while (result == 0) 
            {		
    	        printf("Enter Total Load Resistance in one ohm increments (100-5000)>\n");
    	        scanf("%d", &RL);
    	        if (RL > 5000 )
                    {
    		        printf("\n Invalid value.  The value must be 5000 or less. \n");
    		        result = 0;
                    }
    	        else if (RL < 100)
                    {
    		        printf("\n Invalid value.  The value must be 100 or greater. \n");  
    		        result = 0;
                    }
    	        else
    		        result = 1;
            }
    
            int R2 = 5000;
    
            while (R2 != 0)
            {	
                    R2 = 5000;
    	
                    /*total current*/
                    I = V / (R2 + R1 + RL);
                    printf("Total current is %f amps. \n", I);
    
                    /*Voltage drop across R2*/
                    VR2 = (I * R2);
                    printf("Voltage of R2 is %f VDC. \n", VR2);
    
                    /*Voltage drop across R1*/
                    VR1 = (I * R1);
                    printf("voltage of R1 is %f VDC. \n", VR1);
    
                    /*Voltage drop across load*/
                    VRL = (I * RL);
                    printf("Voltage of load is %f VDC. \n", VRL);
    
                    /*Power drop across R2*/
                    PR2 = I * VR2;
                    printf("Power across R2 is %f watts.  \n", PR2);
    
                    /*Power drop across load*/
                    PRL = I * VRL;
    		
                    if (R2 != 0)
                    {
    		        printf("Power is %f watts.  \n", PRL);
    		        R2 = R2 - 1;
                    }
    		else
    		        printf("Power is %f watts.  Power is at Maximum level. \n", PRL);
            }
            return(0);
    }
    Indentation makes your code a hell of a lot easier to read. The curly braces don't need to be set out as I have (different people have different preferences) but you should always add levels of indentation for anything nested. Good text editors (notepad++ for windows does it) can do this automatically for you if you specify you're using C. IDEs will do it as well.
    Last edited by DeadPlanet; 05-27-2010 at 11:47 PM.

  11. #11
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    You're resetting R2 to 5000 every time you loop around, so it will never reach 0. You made the right change by initialising it before the loop (even though you redeclared it, it will still work) but it seems you forgot to take it out of the loop when you did.

  12. #12
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9
    Ok, I have taken out the repetitive R2 = 5000 inside the loop. I have a statement R2 = R2 - 1 that should decrement R2 by one. Do you think it isn't reading that?

  13. #13
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    What is it printing, what is it getting up to?

    It will never print the final printf("Power is %f watts. Power is at Maximum level. \n", PRL); message because R2 can never be 0 when you get to that point (it should have exited at the beginning). Other than that first glance suggests that it would be working fine.

  14. #14
    Registered User
    Join Date
    May 2010
    Location
    Wichita
    Posts
    9
    I am still getting the error "process returned -1" I can't really see what it is doing beyond that as that is the only thing that appears along with press any key to continue.

  15. #15
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Compiling with MinGW (through Code::Blocks) the code works exactly as I specified in my last post. It works perfectly except that it doesn't print the final Power measurement.

    The process is returning 0.

    Try to paste the code just above into your IDE/editor and compile it as a completely new file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why isn't the execlp() function doing anything?
    By jsrig88 in forum C Programming
    Replies: 5
    Last Post: 10-12-2009, 10:09 AM
  2. sequenceing or queueing multiple process
    By sv_joshi_pune in forum Windows Programming
    Replies: 1
    Last Post: 08-14-2009, 09:43 AM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM