4 Replies - 1692 Views - Last Post: 05 December 2012 - 07:44 AM Rate Topic: -----

#1 Hypernal  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 125
  • Joined: 29-May 12

Process return 0 / Process exited with return value 0

Posted 05 December 2012 - 05:07 AM

The program stops after I inputed a char for the switch/case. It says process return 0;
I'm originally using Code::Blocks then I tried Oswell DevC++ but got the same

#include<stdio.h>
#include<conio.h>
#include<string.h>

main(){

      char user[80], pw[80], let;

      char user1[] = "username1";
      char pw1[] = "password1";
      char user2[] = "username2";
      char pw2[] = "password2";
      char user3[] = "username3";
      char pw3[] = "password3";
      char user4[] = "username4";
      char pw4[] = "password4";
      char user5[] = "username5";
      char pw5[] = "password5";
      char user6[] = "username6";
      char pw6[] = "password6";
      char user7[] = "username7";
      char pw7[] = "password7";
      char user8[] = "username8";
      char pw8[] = "password8";
      char user9[] = "username9";
      char pw9[] = "password9";
      char user10[] = "username10";
      char pw10[] = "password10";

      printf("Enter username: ");
      //let=getche();
      gets (user);

      printf("Enter password: ");
      //scanf("%d", &n);
      gets (pw);

      if((strcmp (user,user1) == 0)&&(strcmp (pw,pw1) == 0)){
                    printf("Welcome User 1!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
      }
      else if((strcmp (user,user2) == 0)&&(strcmp (pw,pw2) == 0)){
                    printf("Welcome User 2!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();

                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }
      else if((strcmp (user,user3) == 0)&&(strcmp (pw,pw3) == 0)){
                    printf("Welcome User 3!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }

      }
      else if((strcmp (user,user4) == 0)&&(strcmp (pw,pw4) == 0)){
                    printf("Welcome User 4!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }
      else if((strcmp (user,user5) == 0)&&(strcmp (pw,pw5) == 0)){
                    printf("Welcome User 5!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }
      else if((strcmp (user,user6) == 0)&&(strcmp (pw,pw6) == 0)){
                    printf("Welcome User 6!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }
      else if((strcmp (user,user7) == 0)&&(strcmp (pw,pw7) == 0)){
                    printf("Welcome User 7!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }
      else if((strcmp (user,user8) == 0)&&(strcmp (pw,pw8) == 0)){
                    printf("Welcome User 8!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }
      else if((strcmp (user,user9) == 0)&&(strcmp (pw,pw9) == 0)){
                    printf("Welcome User 9!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }
      else if((strcmp (user,user10) == 0)&&(strcmp (pw,pw10) == 0)){
                    printf("Welcome User 10!\n");
                    printf("Enter your finished course:\n");
                    printf("[A] BSIT\n");
                    printf("[B] COMPUTER ENGINEER\n");
                    printf("[C] HRM\n");
                    printf("[D] ACCOUNTANCY\n");
                    let=getche();
                    switch(let){
                                    case 'A': case 'a':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Web Developer\n");
                                                        break;
                                    case 'B': case 'b':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Software Engineer\n");
                                                        break;
                                    case 'C': case 'c':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("[Restaurant Manager\n");
                                                        break;
                                    case 'D': case 'd':
                                                        printf("Possible jobs:\n");
                                                        printf("Professor\n");
                                                        printf("Accountant\n");
                                                        break;
                      }
      }

      else{
                printf("invalid username or passowrd");
      }
     getch();
     return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Process return 0 / Process exited with return value 0

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,159
  • Joined: 05-May 12

Re: Process return 0 / Process exited with return value 0

Posted 05 December 2012 - 06:13 AM

What were you expecting to happen?
Was This Post Helpful? 0
  • +
  • -

#3 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: Process return 0 / Process exited with return value 0

Posted 05 December 2012 - 06:16 AM

Few things I wanted to figure out,

First, NEVER use gets(), it is unsafe and very dangerous because it provides no check for buffer overrun... It was deprecated and I think is removed from the standards now...

Use fgets() instead...

Also, you have lots of redundant code. As you are using C, you can have an array of strings like this:
char * userName[2][2];

userName[0][0] = "username1";
userName[0][1] = "username2";

userName[1][0] = "username3";
userName[1][1] = "username4";



Similarly for the passwords. Then you can have nested for loops and on every iteration you can compare the usernames and passwords and execute the switch then...
Was This Post Helpful? 0
  • +
  • -

#4 Hypernal  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 125
  • Joined: 29-May 12

Re: Process return 0 / Process exited with return value 0

Posted 05 December 2012 - 07:16 AM

View PostSkydiver, on 05 December 2012 - 06:13 AM, said:

What were you expecting to happen?


I suppose it should continue to Possible Jobs selection but it's working now.. Thanks anyways! :D

View PostAKMafia001, on 05 December 2012 - 06:16 AM, said:

Few things I wanted to figure out,

First, NEVER use gets(), it is unsafe and very dangerous because it provides no check for buffer overrun... It was deprecated and I think is removed from the standards now...

Use fgets() instead...

Also, you have louots of redundant code. As you are using C, you can have an array of strings like this:
char * userName[2][2];

userName[0][0] = "username1";
userName[0][1] = "username2";

userName[1][0] = "username3";
userName[1][1] = "username4";



Similarly for the passwords. Then you can have nested for loops and on every iteration you can compare the usernames and passwords and execute the switch then...


I want it to be as basic as possible so I didn't use multi-dimensional array. Sorry I didn't knew why I used gets(user) when I can use scanf("%s", &user); instead. Thanks!
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is online

  • member icon


Reputation: 4098
  • View blog
  • Posts: 12,679
  • Joined: 25-December 09

Re: Process return 0 / Process exited with return value 0

Posted 05 December 2012 - 07:44 AM

Using scanf() to extract a character string is almost as bad as using gets(), unless you provide this function with the optional size specifier. Also remember that scanf() will not accept any spaces in your string.

Never, never extract strings without using some method to limit the number of characters you will accept, so you avoid the possibilities of array buffer overrun errors.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1