Super quick ? here

This is a discussion on Super quick ? here within the C Programming forums, part of the General Programming Boards category; Ok awhile ago I posted asking about random characters and delays and such and one guy(unregistered)was nice enough to post ...

  1. #1
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    Super Quick ? here

    Ok awhile ago I posted asking about random characters and delays and such and one guy(unregistered)was nice enough to post his source code. It didn't quite work on my compiler but I decided to give it a try and I worked it down to this last error:

    error C2660: 'textcolor' : function does not take 1 parameters

    I belive that I know what it means but I don't know what to put in the function prototype brackets like one could be:
    void new( double x, double y, double z )

    what is the proper thing to put in the brakets for color?

    Now like I said I tried to get his code to work in my compiler so if things are wrong please tell me, so far though the error mentioned above is the only one, thanks.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <dos.h>
    #include <conio.h>
    
    delay(int);
    randomize();
    clrscr();
    textcolor();
    LIGHTGREEN();
    
    void showwhirl()
    {
        int i, j;
        char whirl[] = {'|','/','-'/*,''*/};
    
        for (i=0;i<=2; i++)
        {
            for (j=0; j<=3; j++)
            {
                printf("%c", whirl[j]);
                delay(20);
                printf("b");
            }
        }
    
    
    }
    
    void printline(char line[30])
    {
        int i;
    
        for (i=0; line[i]; i++)
        {
            showwhirl();
            printf("%c", line[i]);
        }
    }
    
    
    
    main()
    {
        int i;
    
        randomize();
    
        clrscr();
    
        textcolor(LIGHTGREEN);
    
        do
        {
            for(i=1; i<=40; i++)
            {
                cprintf("%c ", 49 + rand()%156);
            }
    
            delay(rand()%250);
    
        } while (!kbhit());
    
        clrscr();
    
    
        printline("Programmed By Maharshi Akilla");
        printf("\n");
        printline("http://mahurshi.tripod.com");
    
        getch();
    
        do
        {
    	} while (!kbhit()); 
    return 0;
    }
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    well, why are you prototyping functions that aren't yours? just include the proper header filers.
    hello, internet!

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Dunno if it's your case, but a textcolor function is defined in conio.h of Borland's line of dos C compilers. It may work in windose, but I'm not positive. It's expecting an integer as an argument in the range of 0-15. Lightgreen is 10 I *think*.

    textcolor(10);

    #define lightgreen 10

    textcolor(lightgreen);
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  4. #4
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Well I don't know what the lightgreen one is(or how to call it till you told me)but I am using Microsofts Visual C++ Introductory one
    I have got to get a Borland compiler, I know there is one on this site, but I need the space, sorry.

    Ok I decided simply to get rid of the lightgreen(just color right?)to see if the code would work and it had LNK2001 error or something, it is the compiler I think cause it says that they probelm comes from a function or variable or something calling something that doesn't exist like a library missing or something...does anyone know what I could/should put in there??
    Last edited by CAP; 08-03-2002 at 01:01 AM.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I am using Microsofts Visual C++
    Visual C++ doesn't support delay(), clrscr(), textcolor(), or randomize(). LIGHTGREEN is prototyped as a function yet I don't see it defined anywhere. This may work a little bit better:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <windows.h>
    #include <conio.h>
    
    void delay ( int milli )
    {
      clock_t end, cur = clock();
      for ( end = cur + milli; cur < end; cur = clock() );
    }
    
    void showwhirl(void)
    {
      int i, j;
      char whirl[] = {'|','/','-','\\'};
      
      for (i=0;i<=2; i++)
      {
        for (j=0; j<=3; j++)
        {
          printf("%c", whirl[j]);
          delay(100);
          printf("\b");
        }
      }
    }
    
    void printline(char line[])
    {
      showwhirl();
      printf("%s\n", line);
    }
    
    
    
    int main(void)
    {
      int i;
      HANDLE STDOUT;
      
      srand ( time ( NULL ) );
      
      STDOUT = GetStdHandle ( STD_OUTPUT_HANDLE );
      SetConsoleTextAttribute ( STDOUT, FOREGROUND_GREEN );
      
      while (!kbhit())
      {
        for(i=1; i<=40; i++)
        {
          cprintf("%c ", 49 + rand()%156);
        }
        delay(rand()%250);
      }
      
      printline("Programmed By Maharshi Akilla");
      printline("http://mahurshi.tripod.com");
      
      getch();
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    here

    textcolor();
    LIGHTGREEN();

    was

    textcolor(LIGHTGREEN);

    MS VC++ may not compile it well.
    You have to change many functions.

    I wrote it and compiled it in TC++ 3

    Mahurshi Akilla
    http://mahurshi.tripod.com
    Last edited by moonwalker; 08-03-2002 at 12:06 PM.

  7. #7
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Ok thanks, I also tried yours Prelude(thanks for taking the time to make a brand new program)and these came up:

    Errors:
    error C2001: newline in constant
    error C2059: syntax error : 'for'
    error C2143: syntax error : missing ';' before ')'
    error C2143: syntax error : missing ';' before '{'

    Warnings:
    warning C4305: 'initializing' : truncation from 'const int' to 'char'
    warning C4309: 'initializing' : truncation of constant value
    warning C4552: '<=' : operator has no effect; expected operator with side-effect

    Now don't bother re-writing anything I got rid of them but I have to ask how this works, all I did(like in my original post with Moonwalkers code)was put comment tags around the ' ' part of that little piece, why was it causing the 'newline in constant'??

    char whirl[] = {'|','/','-'/*,'\'*/};
    Last edited by CAP; 08-03-2002 at 01:08 PM.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I think I am just going to get another compiler but thanks for your help anyways.
    No, it was the board that changed the code I posted. This line:

    >char whirl[] = {'|','/','-','\\'};

    The last item should be an escape sequence of two backslashes, \\. If you make that change it will compile fine.

    -Prelude
    My best code is written with the delete key.

  9. #9
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Looks like my edit was two minutes late

    Thanks though.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  10. #10
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Early versions of MS's C compiler had the header graph.h

    A few of the functions for cursor control were

    _settextcolor(int);
    _outtext("some string");
    _settextposition(x,y); opposite of Borlands gotoxy()
    _clearscreen(options);

    Code:
    #include <stdio.h>
    #include <graph.h>
    
    #define _settextcolor stc
    #define _outtext otext
    #define _settextposition stp
    
    int main(void)
    {  
         stc(10), stp(5,30), printf("This is default colors 0 bg 7 fg");
         
           _clearscreen(_GCLEARSCREEN);
         
            printf("This *should* be green text on a black bg");
          /* but it's been a while since I've used graph.h */
          
           stc(14), stp(12,30), otext("This is yellow on black");   
        
           return 0;
    }
    Graph.h is not in MSVC 6 I believe, nor will it work with win32 console apps. It is strictly for dos text based apps though some fucntions will also work in dos based graphics apps.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 08:48 PM
  2. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 11:33 AM
  3. Questions on basic Quick Sort
    By Weng in forum C++ Programming
    Replies: 4
    Last Post: 12-16-2003, 10:06 AM
  4. With super powers would you:
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-18-2003, 12:27 AM
  5. Quick Sort Help
    By NavyBlue in forum C Programming
    Replies: 1
    Last Post: 03-02-2003, 10:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21