Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with BorlandC

  • 19-10-2008 10:17am
    #1
    Registered Users, Registered Users 2 Posts: 1,164 ✭✭✭


    What is wrong with this? I use BorlandC
    .#include <stdio.h>
    main()

    {
    int v1 ;
    float v2 ;
    char v3 ;
    v1 = 65 ;
    v2 = -18.23 ;
    v3 = 'a'
    printf( "v1 has the value %d\n", v1 ) ;
    printf( "v2 has the value %f\n", v2 ) ;
    printf( "v3 has the value %c\n", v3 ) ;
    printf( "End of program\n" ) ;


    }

    The error i keep getting is
    Error E2379 P2C.c 14: Statement missing ; in function main()
    Warning W8004 P2C.c 20: 'v1' is assigned a value that is never used in function main()
    *** 1 errors in Compile ***
    >Exit code: 1

    help appreciated


Comments

  • Registered Users, Registered Users 2 Posts: 1,512 ✭✭✭stevire


    No semi colon after v3 = 'a'
    so it picks up v3 = 'a' printf( "v1 has the value %d\n", v1 ) as one line of execution!

    :D


  • Registered Users, Registered Users 2 Posts: 1,164 ✭✭✭BaRcOe


    Nice1 thanks stev


  • Registered Users, Registered Users 2 Posts: 1,164 ✭✭✭BaRcOe


    /* Program to introduce variables in C */
    #include <stdio.h>
    main()

    {
    int v1 ; /* v1 is an integer variable */
    float v2 ; /* v2 is a floating-point variable */
    char v3 ; /* v3 is a character variable */
    /* Now assign some values to the variables */
    v1 = 65 ;
    v2 = -18.23 ;
    v3 = 'a' ;
    /* Finally display the variable values on the screen */
    printf( "v1 has the value %d\n", v1 ) ;
    printf( "v2 has the value %f\n", v2 ) ;
    printf( "v3 has the value %c\n", v3 ) ;
    printf( "End of program\n" ) ;

    getchar()
    }


    How about this I get error

    P2C.c:
    Error E2379 P2C.c 20: Statement missing ; in function main()
    *** 1 errors in Compile ***
    >Exit code: 1


    I want to use getchar()
    to make it stay up on the screen?


  • Closed Accounts Posts: 468 ✭✭MrJones


    Barcoe,

    read the error message-

    P2C.c:
    Error E2379 P2C.c 20: Statement missing ; in function main()
    *** 1 errors in Compile ***
    >Exit code: 1

    Its say yu are getting an error on Line 20-
    Also it says the error is -you're missing a ';'
    So go to Line 20 on your code and check it out.
    You'll see getchar() without the semi-colon at the end.


  • Closed Accounts Posts: 5,064 ✭✭✭Gurgle


    BaRcOe wrote: »

    Error E2379 P2C.c 20: Statement missing ; in function main()
    *** 1 errors in Compile ***
    >Exit code: 1
    .
    .
    .
    I want to use getchar()

    Try using:
    getchar();

    Like what the error report says.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,164 ✭✭✭BaRcOe


    Im such a noob:rolleyes:

    What happened was I missed out on the start of programming in College as I got a transfer after my leaving cert results got rechecked and I was offered comp science in d.i.t.

    Im findin it difficult to catch up now but I appreciate your help so much!


  • Closed Accounts Posts: 5,064 ✭✭✭Gurgle


    http://www.functionx.com/cpp/

    ^^ One of the better tutorials on the web.


  • Registered Users, Registered Users 2 Posts: 1,164 ✭✭✭BaRcOe


    What is wrong with this program?

    #include <stdio.h>;
    main[]
    {
    /*Program to illustrate errors in a C program.
    int i, j;
    float i;

    j = 40000;

    PRINTF("The value of i is %d" i);
    PRINT("Size of an integer is %d", sizeof ( int ) ;
    ]


    A FEW adjustments of my own below



    #include <stdio.h>
    main()
    {
    /*Program to illustrate errors in a C program.*/

    int i, j;
    float k;

    j = 40000 ;
    i = 50000 ;
    k = 60000 ;

    PRINTF("The value of i, j is %d, %f\n", i, j ) ;
    PRINT("Size of an integer is %d", sizeof(int));
    }

    Hmm??


  • Registered Users, Registered Users 2 Posts: 1,164 ✭✭✭BaRcOe


    Gurgle wrote: »
    http://www.functionx.com/cpp/

    ^^ One of the better tutorials on the web.

    Im doing C programming:confused:

    will this tutorial not get things mixed up with C++/C?


  • Registered Users, Registered Users 2 Posts: 1,512 ✭✭✭stevire


    BaRcOe wrote: »
    What is wrong with this program?

    #include <stdio.h>;
    main[]
    {
    /*Program to illustrate errors in a C program.
    int i, j;
    float i;

    j = 40000;

    PRINTF("The value of i is %d" i);
    PRINT("Size of an integer is %d", sizeof ( int ) ;
    ]


    A FEW adjustments of my own below



    #include <stdio.h>
    main()
    {
    /*Program to illustrate errors in a C program.*/

    int i, j;
    float k;

    j = 40000 ;
    i = 50000 ;
    k = 60000 ;

    PRINTF("The value of i, j is %d, %f\n", i, j ) ;
    PRINT("Size of an integer is %d", sizeof(int));
    }

    Hmm??


    I'd suggest you get a book, A guide to C Programming by Paul Kelly like the one that is recommended by your course. It is almost a necessity and they have them in the library.

    You can't be learning too much if your asking for help every time you get stuck. A main factor in computer science is problem solving. If you're having problems, google the error code and you'll learn a lot more. Asking for solutions constantly and you'll only fall behind in the understanding of it.

    Ftr, I'm doing computer science in dit... Final year!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    By the way do it as you should:
    int main(int argc, char * argv[])
    {
    :  :  :
    return 1;
    }
    

    The C standard requires you return an integer from your main function. A lot of compilers allow you to do it with void or even nothing from what i see above? - Anyways better do it right from begining.

    And in your code above you are using a print as appossed to a printf. Further more you are using capital printf but as far as I know the C standard when coming to functions is case sensitive - PRINTF != printf. I could be wrong in this however but again good practice to stick to what is standard out there, lower case printf.


  • Closed Accounts Posts: 9,390 ✭✭✭Stench Blossoms


    BaRcOe wrote: »

    PRINTF("The value of i, j is %d, %f\n", i, j ) ;
    PRINT("Size of an integer is %d", sizeof(int));
    }

    Hmm??

    printf on the last line.


  • Registered Users, Registered Users 2 Posts: 1,164 ✭✭✭BaRcOe


    Ye I have that book, its ok, considering im 3 weeks behind its tough learning from that book cuz how do I know to put getchar in to make it keep the screen up after running the program.

    I know i know, ask for help in the labs...etc, I have been and will have to keep doing so until I'm comfortable with the tasks.

    :rolleyes:


  • Closed Accounts Posts: 5,064 ✭✭✭Gurgle


    BaRcOe wrote: »
    Im doing C programming:confused:
    will this tutorial not get things mixed up with C++/C?
    Sure, at about lesson 30 the difference will start to appear. I don't think you need to worry about it just yet.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    BaRcOe have a read of this first. Simpling posting code and asking "Whats wrong with this?" isn't going to get you anywhere fast. As you've said you've a lot of catching up to do - the sooner you start trying to do the work yourself the sooner you'll start learning and start catching up.


  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭SirLemonhead


    return 0 from main rather than 1 to indicate success.

    I don't think it matters much though if you're running the code on windows. still, stick with the convention..


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    yes get into the habbit of returning a correct exit status value for main.

    in recommended text for your course has a void main() with no parameters or no return type :eek:, which is extremely bad programming practice and as far as i am aware some compilers will throw warnings if not errors if they are omitted.


  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    Cremo wrote: »
    yes get into the habbit of returning a correct exit status value for main.

    in recommended text for your course has a void main() with no parameters or no return type :eek:, which is extremely bad programming practice and as far as i am aware some compilers will throw warnings if not errors if they are omitted.
    Here's an interesting newsgroup posting on the whole "void main()" issue


Advertisement