Page 1 of 4 123 ... LastLast
Results 1 to 10 of 38

Thread: C Problems

  1. #1
    Join Date
    Nov 2002
    Posts
    2,231
    Rep Power
    0

    Default C Problems

    I am running Borland 5.02
    I am having a problem and hope for the help. Firstly with borland. Everytime i run a program i have made... the stupid thing closes without allowing me to see the results. Well at least the results show... but only for .5 second..... which means i dont get to see anything to make sure im completely and positively correct.

    Next question i have is that i would like to add some flavour to my project's presentation, in that the main menu... is just simple and straight forward text with some asteriks around it. Can somebody tell me how to change the font of my texts in my main and also simple things such as background colours or inserting images in C.

    Final question, about the project, after you have accessed any part of the menu and done all the calculations you want to do, how do i get the program to go back to the menu page... without having the user enter some value... how about just wen he presses enter... things like that.

    Help will be greatly appreciated
    Laptop: HP DV6700t - Core 2 Duo T9300 2.5Ghz, 3GB RAM, Nvidia 8400m GS, 250GB HDD. Ubuntu 12.04 and Windows 7
    Phone: Samsung Galaxy Nexus

  2. #2
    Join Date
    Aug 2004
    Posts
    2,789
    Rep Power
    0

    Default Re: C Problems

    Quote Originally Posted by Skillachi
    I am running Borland 5.02
    I am having a problem and hope for the help. Firstly with borland. Everytime i run a program i have made... the stupid thing closes without allowing me to see the results. Well at least the results show... but only for .5 second..... which means i dont get to see anything to make sure im completely and positively correct.
    You need to use getch to hold the screen,
    put the header file #include<conio.h> below #include<stdio.h>
    and before the end of the program where u have the return put:
    getch();
    The views expressed in the above post are not neccesarily the views of icuucme.

  3. #3
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default Re: C Problems

    I am running Borland 5.02
    I am having a problem and hope for the help. Firstly with borland. Everytime i run a program i have made... the stupid thing closes without allowing me to see the results. Well at least the results show... but only for .5 second..... which means i dont get to see anything to make sure im completely and positively correct.
    apart from getch(); use can type system("pause"); jus include the stdlib.h library.

    Next question i have is that i would like to add some flavour to my project's presentation, in that the main menu... is just simple and straight forward text with some asteriks around it. Can somebody tell me how to change the font of my texts in my main and also simple things such as background colours or inserting images in C.
    if u using borland (which u are) you can change the console background using textbackground function in the conio.h library textcolor to change the text color. for example to change the background to blue and textcolor to yellow you could do something like this:

    textbackground(BLUE);
    textcolor(YELLOW);

    note: if you change the text color using the textcolor function you will have to use cprintf function instead of printf function to get the text printed in color.

    I really don't remember how to change the text font (If it was easy i would). Inserting images into the console window.. uhmm thats propably too much for what u are trying to do and is definately no an easy task. oh yea i don't know how to do that with a console window.

    Final question, about the project, after you have accessed any part of the menu and done all the calculations you want to do, how do i get the program to go back to the menu page... without having the user enter some value... how about just wen he presses enter... things like that.
    If i understand this correctly, basically you are asking for a way to cancel the function or return to the main menu if the user pressed something like Esc.

    uhhmm well you would have to devise some method of recording every key stroke by the user. u could do that with the getch() function. However you would have to do extra coding to detect when the user had entered a complete number. a possible code would be.
    Code:
    char buffer[256];
    char c;
    int i = 0;
    int num;
    
    while( (c = getch() ) != 27 ) {  //27 is the ascii code for the Esc key.
        if(c == 13) { //13 ascii code for the return key
           break;
        }
        buffer[i] = c;
        ++i;
    }
    
    if( c == 13 ) {
        buffer[i+1] = '\0' //terminate the string;
        num = atoi(buffer); //convert the string into a number.
    }
    else() {//the user hit the Esc key..
        //return to the main menu
    }
    that way you will definately know if the user had press the Esc key to cancel or the return key to complete the entry of a number.

  4. #4
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default Re: C Problems

    if you were using the greatest compiler and IDE ever made you wouldnt have to do childish things like those, visual studio.net doesn't have problems like that, but is a price IDE still i got it from imp we got it with out laptops [ had to pay some crappy liscening fee too i think ]

  5. #5
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default Re: C Problems

    I don't think he has a choice.. that sound like sch work.. also hes working with standard c it seems, its very limited in functionality, nowhere near to what we know in languages we use today. But on the flip side I think Visual Studio is crap. If you ask me nothing beats Eclipse..

  6. #6
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default Re: C Problems

    hmm i'm gonna google that eclipse now, i really never came across an ide more robust that visual studio.net still, i gotta be honest but i'll check out this eclipse.

  7. #7
    Join Date
    Sep 2002
    Posts
    3,270
    Rep Power
    0

    Default Re: C Problems

    for portability sake it is best to use a system call such as
    Code:
     system('pause');
    because if you use getch(); you code will not work on a Unix/Linux platform as getch() is a strictly dos library construct. DOS did not have a pause command at the time getch was written

    When porting over the code to say Linux you can replace
    Code:
    system('pause');
    with
    Code:
    system ('sleep -3s');
    Last edited by Gillion; Mar 22, 2005 at 12:54 AM.
    Those who do not understand UNIX are doomed to reinvent it poorly.

  8. #8
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default Re: C Problems

    spash.h is found here
    http://codecentral.borland.com/ccweb...sting?id=15932
    I have not tested the link as it is for Borland users. I think it does a splash screen

    If you have wincon.h then you may be able to use
    SetConsoleTextAttribute
    WriteConsoleOutputAttribute
    ReadConsoleInput

    The last funtion can be configured to read mouse input or key input. You check a buffer which stores events. I dont use it, so I do not know bout it. I use directX and if it works like directx, then it fills a buffer with the input events since the last time the buffer was looked at and emptied. The buffer can fill up if it is not checked periodically, so looping may work.

    If you do not want to use that, then console i/o <conio.h> is the one I would suggest for getting the user to close the application with a key button. (you could save characters the user types into a buffer, and periodically search the entire buffer for a 'closing' character).
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  9. #9
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default Re: C Problems

    Quote Originally Posted by Gillion
    for portability sake it is best to use a system call such as
    Code:
     system('pause');
    because if you use getch(); you code will not work on a Unix/Linux platform as getch() is a strictly dos library construct. DOS did not have a pause command at the time getch was written

    When porting over the code to say Linux you can replace
    Code:
    system('pause');
    with
    Code:
    system ('sleep -3s');
    Code:
    > sleep -3s
    sleep: Specify time as a positive integer.
    I guess that only works on linux.

    Anyway I must apologize in advance but I am an avid C programmer, C is my first
    language, then english comes next .

    For a completely portable solution, from borland -> visual -> gcc -> cc -> lcc..
    one should implement that getch/pause functionality using select() polling for input
    from the stdin file.

  10. #10
    Join Date
    Nov 2002
    Posts
    2,231
    Rep Power
    0

    Default Re: C Problems

    ok thanx i used the pause thing... and it worked so happiness reigns for that.
    I decided not to use the getch thing because of gillions warning and even though i know it will not be tested on linux/unix based system i still wanna be compatible.

    LEOANDRU THANX MUCHAS FOR THAT ASCII KEY THING DAT HAAAAAAAAAAAAAAAAARD !!! can you tell me the ascii equivalent codes for like... all the keys on the keyboard or gimme a link to them... (i mus get at least a 95% now... mwahahahaha)

    And my final question, when i use the ascii code does case still matter... as in lets say the ascii code for the letter "g" is 20... if the person say enters G would the ascii be 21? or would it still be read as 20?
    Laptop: HP DV6700t - Core 2 Duo T9300 2.5Ghz, 3GB RAM, Nvidia 8400m GS, 250GB HDD. Ubuntu 12.04 and Windows 7
    Phone: Samsung Galaxy Nexus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •