Sami_codes_AllDay's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Contributors
Active Posts:
37 (0.03 per day)
Joined:
09-August 11
Profile Views:
1,049
Last Active:
User is offline Feb 04 2013 08:28 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Nintendo
Your Car:
Who Cares
Dream Kudos:
50
Icon   Sami_codes_AllDay If you're not confused and scratching your head, then you're not tackling difficult enough problems...

Posts I've Made

  1. In Topic: Menu Guided UI - Switch Statement

    Posted 4 Feb 2013

    Hi Raghav,

    Here is the code where the 'default' case is always asserted:


    
    #define TRUE   1
    #define FALSE  0
    
    
    int main()
    {    
    	 
      char user_input = 0;
      bool loop_flag = TRUE;
    	 
    	    do{
    	    printf(" Press 0 for Jupiter\n\n");
    	    printf(" Press 1 for Earth\n\n");
    	    printf(" Press 2 for Mars\n\n");
    	    printf(" Press 3 for Venus\n\n");
    	    printf(" --> Any key other than '0'-'3' To Exit Console Application <-- \n\n");
    	 
    	     
    	    printf("\n\nEnter your choice here --> ");
    	    scanf("%c", &user_input);  // scans for an unsigned short
    	 
    	 
    	    switch(user_input)
    	    {
    	     
    	    case '0':
    	        printf("\nHello Jupiter!\n");
    	        break;
    	 
    	    case '1':
    	        printf("\nHello Earth!\n");
    	        break;
    	 
    	    case '2':
    	        printf("\nHello Mars!\n");
    	        break;
    	 
    	    case '3':
    	        printf("\Hello Venus!\n");
    	        break;
    	 
    	    default:
    	        loop_flag = FALSE;
    		printf("\nLoop flag now = false, menu should now exit gracefully.\n\n");
    	        break;
    	    }
    	     
    	 } while(loop_flag);
    	 
    	 
    printf("\nExiting Win32 Console Application.\n\n");
    system("Pause");  // Hold the console window open --> "Press any key to continue"
    
    
    	return 0;
    	}
    
    
    


    Thanks.

    Best,

    SB
  2. In Topic: Menu Guided UI - Switch Statement

    Posted 4 Feb 2013

    Thanks Raghav,

    Your suggestion was very helpful. I had a feeling that I was mixing up my types (char and unsigned short int) for the variable user input. I went ahead and implemented your suggestion using the loop flag, however, now, the default case is always asserting. Just FYI, my "true" = 1, my "false" = 0, and each case statement has ' ' around the alphanumeric to signify that it's a character. I'm also using:

    scanf("%c", &user_input);
    user_input = getchar();

    and getting the same result...

    default:
              printf("\nThis case is now always asserting and the loop is breaking always.\n\n");
              flag=false;
              break;
    
    



    confounding...hmmm.


    Best,

    SB
  3. In Topic: Saving The State Of A Pointer to a Struct

    Posted 28 Dec 2012

    Thank You Good People,

    Aphex, I think Baavgai brings up a point that is of central concern here, and that is, saving the state of 'myVar.string'. If myVar.string is continually being modified within foo() and foo_bar() by-reference, will a static local variable 'static CoolDataType save;' really save the string (myVar.string)? Again, thank you for your intelligent insights!

    
    int main() 
    {
      CoolDataType myVar;
      static CoolDataType savedState;   // This is now static
      int x = 50;
    	 
      for(;;)/>/> { // this would be the double ; infinite loop
    	        foo(&myVar);
    	        foo_bar(&myVar);
    	        if (x > randNumGenerator()) {
    	            savedState = myVar; // Does this really work for strings?
                        savedState.string = myVar.string; // Why won't this will? hmm
    	        }
    	    }
    	    return 0;
    	}
    
    
    
  4. In Topic: Writing a GUI for an application in C

    Posted 20 Sep 2012

    Hi SkyDiver,

    Thank you for the valuable advice. Within a Windows environment, is it possible to simply write a frontend (in C#, VB.NET, etc)without the DLL compilation? I guess what I'm saying is, what is the necessity for the DLL compilation? Thanks.

    Best,

    Sami

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
13
Programming Languages:
C/C++, PERL, Matlab, VB (if you bend my arm)

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

Sami_codes_AllDay has no profile comments yet. Why not say hello?