Thread: Dev C++ question

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    22

    Dev C++ question

    I have been trying to learn C via self-study. I have been reading this forum for a couple months now and have purchased a couple books on C, as well as a training course on CD. I have Dev C++ version 4.9.9.2 and have a question pertaining to the use of comments in the IDE.

    I thought that the C++ style comment style (//) was adopted in the latest ANSI C standards, in place of the traditional (/*) commenting symbols. However when I try this the compiler does not like it...what I am doing wrong? What setting in the 'Tools' menu do I need to enable to allow this style of commenting; if it is indeed possible?

    Any help would be greatly appreciated.

    Thanks.

    TCB

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Works for me in a newly created C console project.
    Can you post your program?

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    Code:
    //
     /*      Course_Project.c
     *
     *      Program to maintain a database of CDs for a record store.
     *      This is the Course Project for the C Programming Course
     *
     *
     *     by snidely whiplash, 2006.
     */
     //
    #include <stdio.h>
    #include <ctype.h>
    
    main()
    {
        char    title[100][61];
        char    artist[100][61];
        int     tracks[100];         /* number of tracks on the CD */
        char    type;                /* used to read in album/single info */
        int     album[100];          /* boolean - is the CD an ALBUM? */
        float   price[100];
        int     i, j;
        int     records = 0;
        int     count = 0;
    
        printf("Welcome to the CD database.\n\n");
        printf("How many CDs do you want to enter? ");
        fflush(stdin);
        scanf("%d", &records);
        printf("\nPlease enter the details of the CD...\n");
    
        for (i = 0; i < records; i++)
        {
            /*Get the artist*/
            printf("Artist? ");
            fflush(stdin);   /*this means to flush anything from...*/
            scanf("%[^\n]", artist[count]);     /*The [^\n] means "read...*/
    
            /*Get the title*/
            printf("Title? ");
            fflush(stdin);
            scanf("%[^\n]", title[count]);  /*must use the [^\n]...*/
    
            /*Get the number of tracks*/
    
            printf("Number of tracks? ");
            fflush(stdin);
            scanf("%d", &tracks[count]); /*Need the '&' now...*/
            if (isdigit(tracks[count]))
                
                
            /*else
                    printf("Error!\n");*/
                   
                    
            /*Is this an Album (a) or Single (s)?*/
            for ( ; ; ) /*forever loop--continues until the user...*/
                {   
                    printf("Album or single ('a' for album, 's' for single)? ");
                    fflush(stdin);
                    scanf("%c", &type);
                    if (type == 'a' || type == 's') /* If type == 'a' or type...*/
                        break;
                    else
                        printf("Error!\n");
                }
            album[count] = type == 'a';
            
            /*Get the price*/
            printf("Retail price (e.g. 4.65)? ");
            fflush(stdin);
            scanf("%f", &price);
            
            /*increment the counter for the record count*/
            count = count + 1;
       }     
       
            /*Output the CD details*/
            for (i = 0; i < count; i++)
            {    
                printf("\nThe CD details you entered are:\n");
                printf("==============================\n");
                printf("Artist: %s\n", artist[i]);
                printf("Title: %s\n", title[i]);
                printf("Number of tracks: %d\n", tracks[i]);
                if (album[i])
                    printf("Album\n");
                else
                    printf("Single\n");
                printf("Price: %.2f\n", price[i]); /*Print the price with two decimal places*/
                printf("The value of 'i' is: %d\n", i);
                printf("==============================\n");
            }
            
        /*A user-friendly exit of the program*/
        printf("\nPress ENTER to exit the program: ");
        fflush(stdin);
        getchar();
    }
    This is one of the programs I have been working on for the CD course in C I have been learning from. But it does not compile for me with the '//' in the file header; though it did with the '/*...*/'

    But I did not use a console application to create it. After reading your post, I *did* try to open a console application and try to compile with the C++ commenting symbols...and it worked. But why?

    Thanks for the help.

    TCB
    Last edited by TCB; 04-08-2006 at 09:03 PM.

  4. #4
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    The problem isn't the assumed lack of the compiler's ability to parse // comments.
    Code:
    */      by Tom Betka, 2006.
    Your signature is outside the block comment.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    No, that's not the problem...lol.

    I edited the above code incorrectly, and forgot to close the comments. My mistake. I assure you, it was correct in my source code before I posted it, then I changed it for clarity (helped a lot, didn't it?). But the compiler 'errored' the very first line with the '//'.

    I will try to edit the above code to what I *meant* to say.

    Apologies for the confusion. That will teach me to try to simplify things!

    TB

    EDIT: Here you go. This will not compile using my current configuration of Dev C++ 4.9.9.2. (I included only a short segment for brevity.)

    Code:
    //
    
    /*      Course_Project.c
     *
     *      Program to maintain a database of CDs for a record store.
     *      This is the Course Project for the C Programming Course
     *
     *      by snidely whiplash, 2006.
     */
    #include <stdio.h>
    #include <ctype.h>
    
    main()
    {
        char    title[100][61];
        char    artist[100][61];
        int     tracks[100];         /* number of tracks on the CD */
        char    type;                /* used to read in album/single info */
        int     album[100];          /* boolean - is the CD an ALBUM? */
        float   price[100];
        int     i, j;
        int     records = 0;
        int     count = 0;
    }
    Last edited by TCB; 04-08-2006 at 09:02 PM.

  6. #6
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    Well C++ style comments were introduced to C in the C99 standarnd which is not widely supported but the most compilers usually allows you to use them anyways. As for Dev-C++ I tried compiling your code with MinGW (which is the compiler Dev-C++ uses) and got no errors, however, if the -ansi flag is given then you'll get errors. Check if Dev-C++ uses it.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    As Dante mentioned above, if you open a console project and use them, it works just fine. But I wasn't using the console project until now. So I guess I need to go investigate the different project types in Dev C++...

    Is there a tutorial on that IDE around here somewhere? I have looked a bit but haven't found one yet.

    Thanks.

    TB

  8. #8
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Quote Originally Posted by OnionKnight
    As for Dev-C++ I tried compiling your code with MinGW (which is the compiler Dev-C++ uses) and got no errors, however, if the -ansi flag is given then you'll get errors. Check if Dev-C++ uses it.
    Dev-C++ doesn't use -ansi by default for either C or C++ console projects.

    Quote Originally Posted by TCB
    But I wasn't using the console project until now. So I guess I need to go investigate the different project types in Dev C++...
    Can you replicate the error? If you can, tell us

    1) Which project type you use AND
    2) What language you're using AND
    3) Source code you used

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    I used the C source code above; neither example compiles. And I think the file I used was simply in the file path File:New:Source File (Ctrl+N). I don't think I actually created a project because I only have a single file.

    The way I read the Dev C++ 'help' section on project types, you can use the Ctrl+N command to open a new file suitable for source code. And since it works just fine for everything else (*except* the C++ style comment symbols that is), I guess I figured that it was the right one to use.

    Maybe I just need to open a console project from here on out, as it seems to work just fine?

    TB

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    Code:
    //      File:
    // 
    //      Program Details:
    //     
    //      Author: 
    //
    //      Date:
    //
    
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
          
      system("PAUSE");	
      return 0;
    }

    OK, I created the above file template to do the course "assignments" that are on the CD. I used a console application and it compiles just fine. So I guess I will just use this from now on--in place of the new source file option I described above.

    I don't understand the parameters listed for the main() though--I understand that it returns an int type, and that it accepts both an int and a char. But the course I am working through hasn't discussed the argc or *argv[] parameters. Hopefully it will make sense soon enough; but it will sure be nice to use the C++ commenting characters.

    Thanks for all the replies folks.

    TB

  11. #11
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Quote Originally Posted by TCB
    I don't understand the parameters listed for the main() though--I understand that it returns an int type, and that it accepts both an int and a char.
    It actually accepts an int, and an array of pointer-to-null-terminated strings.

    Arguments to main

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    Thank you Dante...nice link!

    TB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 01:05 AM
  3. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 08:43 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM