Thread: want to know error in the program ... plz help ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    6

    want to know error in the program ... plz help ...

    Code:
    #include<stdio.h>
    #include<dos.h>
    #include<conio.h>
    
    
    void main()
    {
    int x=1;
    
    
     for(int i=i;i<10;i++)
    {
              textcolor(i+1);
    cprintf("%c \t  %d \t \t",x,x);
     x++;
     }
    }

  2. #2
    Registered User
    Join Date
    Apr 2012
    Posts
    6
    it is showing me this error...
    Compiling NONAME00.CPP:
    Error NONAME00.CPP 13: Call to undefined function 'textcolor' in function main()
    Error NONAME00.CPP 14: Call to undefined function 'cprintf' in function main()

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,896
    Well, dos.h and conio.h are ancient headers that don't appear to be supported by your compiler anymore, thus you can't use textcolor or cprintf. At least it's a good sign you're NOT using Turbo C. Look at the documentation for current functions that do the same thing: Console Functions.

    Also, on line 11, what is the value of i the first time through the loop? That's right, it's random garbage! You need to initialize it to something reasonable, like 0 or 1.

  4. #4
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Andruil I thought C does not support local declarations within a for loop? Is there an earlier standard that supported this?
    ex: for(int i=0;.....)

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,896
    Quote Originally Posted by camel-man View Post
    Andruil I thought C does not support local declarations within a for loop? Is there an earlier standard that supported this?
    ex: for(int i=0;.....)
    No, standard support for that started with C99. It's often disabled or warned about by default though, since many popular compilers only have partial support for C99.

    IIRC, the older standard, C89 didn't support mixed declarations at all, meaning all variable declarations had to be at the top of the function.

  6. #6
    Registered User
    Join Date
    Apr 2012
    Posts
    6
    i am using borland version 4.5 ... when opened the help ... it shows me that type of declaration only ... is their any alternative for it ..
    and yeah .. line 11 error .. got it .. started it with 0 .. typing error while posting it here...

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,896
    You mean the help files show you the declaration of i inside the for loop? If that works, then keep using it. If it doesn't, you can just put int i; at the top of the funciton and take it out of the for loop:
    Code:
    int i;
    for (i = 0; i < 10; i++)

  8. #8
    Registered User
    Join Date
    Apr 2012
    Posts
    6
    not the for loop ... i am saying it for dos.h .. and cprintf .. etc..

  9. #9
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,896
    Ahh, okay. Well, there is no portable way, but for Windows, check out the console functions: Console Functions. I'm not a Windows programmer though, so that's as far as my knowledge goes.

  10. #10
    Registered User
    Join Date
    Apr 2012
    Posts
    6
    i tried to read that ... but it all goes over my head...
    will it run if i try in linux?? ubuntu(11.10) ??

  11. #11
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by Dhruv Aggarwal View Post
    i tried to read that ... but it all goes over my head...
    will it run if i try in linux?? ubuntu(11.10) ??
    No. Because it's Windows-specifc. That implies it will only work on Windows.

    For Linux, drop `dos.h` and `conio.h`, and use standard `printf()` instead of `cprintf()`. Forget about `textcolor()` and see this link about how to get some color into your shell.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  12. #12
    Registered User
    Join Date
    Apr 2012
    Posts
    6
    Quote Originally Posted by msh View Post
    No. Because it's Windows-specifc. That implies it will only work on Windows.

    For Linux, drop `dos.h` and `conio.h`, and use standard `printf()` instead of `cprintf()`. Forget about `textcolor()` and see this link about how to get some color into your shell.
    ok .. it didnt worked well on windows....
    Code:
    #define BRIGHT 1
    #define RED 31
    #define BG_BLACK 40
    printf("%c[%d;%d;%dmHello World", 0x1B, BRIGHT,RED,BG_BLACK);
    shows me this error
    Compiling NONAME00.CPP:
    Warning NONAME00.CPP 4: Style of function definition is now obsolete
    Error NONAME00.CPP 4: ) expected

  13. #13
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    You have some typos in your printf unless you need that '[' and the 'm' embedded in your printed string.

  14. #14
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,896
    That method msh gave you was for Linux.

    Well, what you have is not a complete program. There is no main function, and no #include statements for example. So either you need to make that a complete program and try compiling again, or you need to post the real program with the real errors and real line numbers.

    As for console colors in general, you have a few options:

    1. You are writing this for Windows only. Use the link I gave you in post #9. In there is a function called SetConsoleTextAttribute. That's what you want. Google for examples.
    2. You are writing this for Linux only, and DONT have ncurses. Use the link provided by msh in post #11, though this is highly unportable.
    3. You are writing for Linux and/or Windows. Use a curses library like ncurses/pdcurses. This is the most portable (there will be some small differences), but requires a bit more work to get things up and running. Google for examples.

  15. #15
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,896
    Quote Originally Posted by slingerland3g View Post
    You have some typos in your printf unless you need that '[' and the 'm' embedded in your printed string.
    Those aren't typos. They're terminal escape sequences, and can be used to set terminal colors, etc. They were discussed in the link msh provided in post #11.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-28-2011, 11:48 AM
  2. Replies: 13
    Last Post: 11-03-2010, 12:45 PM
  3. C Program... Program or Compiler error?
    By Zemira in forum C Programming
    Replies: 13
    Last Post: 12-02-2009, 08:59 PM
  4. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  5. i'm trying to fix an error with my error messaging on my program
    By RancidWannaRiot in forum C++ Programming
    Replies: 10
    Last Post: 09-30-2003, 01:02 PM