Thread: using a driver function to test my code??

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I am actually using Microsoft Visual C++ 6.0 compiler
    A bit better than what I feared you were stuck with, but not much

    Do you use projects, or do you just type
    cl prog.c
    in a command line box?

    Projects
    Locate projects->settings C/C++ (I think)
    one of the options configures the warning level.

    Command line
    Start with
    cl /?
    to get a list of options. I think the warning level is
    cl /W4 prog.c
    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.

  2. #17
    Registered User
    Join Date
    Mar 2004
    Posts
    78
    All I do when I start Visual C++ is go to New, then Files, then C++ source file and I type and compile the code. I don't even use the command line. Is there something I should be doing that would help me? Like adjusting the settings? When I went to project and settings, the settings are grayed out and I cannot select it. Probably because I am going into the project. I have only used Microsoft Visual C++ 6.0 to create and compile Visual Basic programs. I have used this compiler through Visual Basic and Advanced Visual Basic and so far, I like it. So why spend money to buy another compiler when this one works fine? I first installed the Borland Compiler, but I really didn’t care for it and I had trouble setting it up to work properly on my computer. If there are settings that I should adjust or change that will help me, as a student, learn more, I would like to know. Thanks......

  3. #18
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    When you are working on a new project, start off by creating a new project. If you don't then it'll automatically make one when you try to compile a file. Then once you're done that the Project Settings should no longer be greyed out.

    Go to C/C++->General
    and set warning level to level 4.
    Also in category Customize, check the box marked 'disable language extentions'

    There are better compilers which are free, but the development environment in Visual Studio is excellent. Stick with what you've got.

  4. #19
    Registered User
    Join Date
    Mar 2004
    Posts
    78
    Awesome...thanks for the tip

  5. #20
    Registered User
    Join Date
    Mar 2004
    Posts
    78
    I still dont understand what this means:

    If ch is not a digit between '0' and '9', then the function returns a value of 0. Otherwise......................followed by a newline character and has a return value of 1. The program is complete, except for this part.

    Sorry for asking again, but I am alittle consfused. Thanks again. You all have been a great help. tommy

  6. #21
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Originally posted by tommy69
    I still dont understand what this means:

    If ch is not a digit between '0' and '9', then the function returns a value of 0. Otherwise......................followed by a newline character and has a return value of 1. The program is complete, except for this part.

    Sorry for asking again, but I am alittle consfused. Thanks again. You all have been a great help. tommy
    Post your code.

    Your writeNumber function should return 0 if the user typed a number, or 1 if they didn't.

  7. #22
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by tommy69
    I still dont understand what this means:

    If ch is not a digit between '0' and '9', then the function returns a value of 0. Otherwise......................followed by a newline character and has a return value of 1. The program is complete, except for this part.
    Is there some important information removed from your post where "......................" is? That sentence doesn't read correctly and I fear there may be important information missing.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  8. #23
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Originally posted by WaltP
    Is there some important information removed from your post where "......................" is? That sentence doesn't read correctly and I fear there may be important information missing.
    First post:
    I need to create a function called writeNumber() using the switch statement. The input argument is ch of type char. Now, if ch is not a digit between '0' and '9', then the function returns the value 0 (I can use the isidigit() function). Oherwise, the function writes to the screen the correct English word of the digit charatcer followed by a newline charatcer and has a return value of 1. Once I write the function, I have to use the following driver to test my function:

  9. #24
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Thanks for the full explanataion. I wasn't looking forward to rereading the entire thread just to find out what was missing.

    This simply means if the character is not a digit, the function returns the value 0 indicating an illegal value.

    If the character is a digit, display the word indicating the digit ("one\n", "two\n", etc.) In this case, the function returns the value 1 indicating a legal value.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  10. #25
    Registered User
    Join Date
    Mar 2004
    Posts
    78
    Thanks Major_blagger...I didnt get to the post quick enough as I would of explained the............. Here is my code. If the user types in a letter, the driver function prints "That wasn't a number key!" Once the word is printed, say "One", I have the \n, but is it returning a value of 1? Why is it or why is it not? The bottom of the code has else x=0, meaning that if the user types anything but a digit, then x=0. Hope this is correct. Thanks for your help.

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <conio.h>
    
    int writeNumber(int);
    
    void main()							/*DRIVER FUNCTION*/
    {
    	char ch;
    	int num;
    
    	printf("Hit any number key>>");
    	ch=(char) getch();
    	printf("\nYou entered %c>>",ch);
    
    	num=writeNumber(ch);
    	if (num==0)
    		printf("\nThat wasn't a number key!\n");
    }
    
    int writeNumber(int x)
    {
    
     if (isdigit (x)) /* If input equals a number,perform the switch statement */
    
    	switch (x)
    	{
    	case '0':
    		printf("Zero\n");
    		break;
    	case '1':
    		printf("One\n");
    		break;
    	case '2':
    		printf("Two\n");
    		break;
    	case '3':
    		printf("Three\n");
    		break;
    	case '4':
    		printf("Four\n");
    		break;
    	case '5':
    		printf("Five\n");
    		break;
    	case '6':
    		printf("Six\n");
    		break;
    	case '7':
    		printf("Seven\n");
    		break;
    	case '8':
    		printf("Eight\n");
    		break;
    	case '9':
    		printf("Nine\n");
    		break;
    	}
    	else   x=0;	/* If user types anything but a number, x = 0 */
    		
    	 			
    	return (x);	 /*x is returned to the function */
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM