Thread: Structures, passing array of structures to function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    if(major!='e'||'h'||'m'||'c'||'b'||'u'){
    			printf("ERROR! Invalid Error Code Entered\n");
    			count--;
    		}
    You are comparing major to 1.
    Code:
    if(major!='e'||major!='h'||major!='m'||major!='c'||major!='b'||major!='u'){
    			printf("ERROR! Invalid Error Code Entered\n");
    			count--;
    		}
    Keep the switch and make this the default.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by Dave_Sinkula
    Code:
    if(major!='e'||'h'||'m'||'c'||'b'||'u'){
    			printf("ERROR! Invalid Error Code Entered\n");
    			count--;
    		}
    You are comparing major to 1.
    Code:
    if(major!='e'||major!='h'||major!='m'||major!='c'||major!='b'||major!='u'){
    			printf("ERROR! Invalid Error Code Entered\n");
    			count--;
    		}
    Keep the switch and make this the default.
    Thats not working either for some reason.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    D'oh! I knew I should have spent more time before posting. The || need to be &&.

    Or again, go with the switch.
    Code:
       switch ( major )
       {
       case 'e': case 'h': case 'm': case 'c': case 'b': case 'u':
          /* do stuff */
          break;
    
       default:
          printf("ERROR! Invalid Error Code Entered %c\n", major);
          return 0;
       }
    Last edited by Dave_Sinkula; 04-05-2006 at 03:20 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by Dave_Sinkula
    D'oh! I knew I should have spent more time before posting. The || need to be &&.

    Or again, go with the switch.
    Code:
       switch ( major )
       {
       case 'e': case 'h': case 'm': case 'c': case 'b': case 'u':
          /* do stuff */
          break;
    
       default:
          printf("ERROR! Invalid Error Code Entered %c\n", major);
          return 0;
       }
    Oh, I should have figured that out. Thanks.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    5
    Code:
    scanf("%s",&person);
    incorrect i belive it should be
    Code:
    scanf("%s",person);
    Its an array. so u dont need the &

    anyways its probably not the major concern

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by tama00
    Code:
    scanf("%s",&person);
    incorrect i belive it should be
    Code:
    scanf("%s",person);
    Its an array. so u dont need the &

    anyways its probably not the major concern
    Hmm.. It seems to work either way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-31-2009, 02:44 PM
  2. passing an array to function
    By waysgoose in forum C++ Programming
    Replies: 2
    Last Post: 07-22-2008, 03:59 AM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  5. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM