<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>C and C++ Forum RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest threads from the 'C and C++' forum at Programmer's Heaven, excluding replies.</description>
    <language>en</language>
    <copyright>Copyright 2009 Programmers Heaven</copyright>
    <pubDate>Fri, 03 Jul 2009 18:14:58 -0700</pubDate>
    <lastBuildDate>Fri, 03 Jul 2009 18:14:58 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Help on homework assignment</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/393263/393263/help-on-homework-assignment/</link>
      <description>I need to write a function called distance that calculates the distance between two points (x1,y1) and (x2, y2). All numbers and return values should be of type double. &lt;br /&gt;
&lt;br /&gt;
Here is what i have so far.&lt;br /&gt;
&lt;br /&gt;
#include "stdafx.h"&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
	double x1,x2,y1,y2,d;   //declaring variables&lt;br /&gt;
&lt;br /&gt;
	cout &amp;lt;&amp;lt; "Please enter the first two points\n";  //prompting usering for the first two points.&lt;br /&gt;
	cin &amp;gt;&amp;gt; x1 &amp;gt;&amp;gt; y1;&lt;br /&gt;
&lt;br /&gt;
	cout &amp;lt;&amp;lt; "Please enter the last two points\n";   //prompting the user for the last two points.&lt;br /&gt;
	cin &amp;gt;&amp;gt; x2 &amp;gt;&amp;gt; y2;&lt;br /&gt;
    &lt;br /&gt;
        //distance function&lt;br /&gt;
        double distance(double x1, double x2, double y1, double y2)&lt;br /&gt;
	{&lt;br /&gt;
                 d = (sqrt (pow (double X2) - (double X1) ) + ( pow (double Y2) - (double Y1));&lt;br /&gt;
		 return d;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/393263/393263/help-on-homework-assignment/</guid>
      <pubDate>Fri, 03 Jul 2009 16:54:37 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>how to do a sequential search in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/393261/393261/how-to-do-a-sequential-search-in-c/</link>
      <description>I'm trying to do a binarysearch in this piece of code that i have here. if the array has been sorted use a binary search, if it is not sorted use a sequential search. I've manage to get the binarysearch section of the code working, however, no joy with the sequential search.&lt;br /&gt;
&lt;br /&gt;
Can anyone show show me to accomplish this? i'm a newbie to the language, and i'm still learning this stuff. maybe a starting point, then i might be able to figure out the rest of it out myself.&lt;br /&gt;
&lt;br /&gt;
thanks&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;ctype.h&amp;gt;//needed for toupper function
#include &amp;lt;time.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#define SIZE 5


char menuVersion1 ();
void  menuVersion2 (char *);
void fill ( int [] , int * );// void fill ( int * );
void print ( int [] );
void sort ( int [] , int *  );

int main ()
{
    char selection;
    int A [SIZE] = {0}; // A is an array of 5 integers
    int sorted = 0;
    
    srand ( time (NULL) );

    do
    {
      //selection = menuVersion1 ();
      menuVersion2 ( &amp;amp;selection );
      
      

      switch ( selection )
      {
         case 'F' : fill (A , &amp;amp;sorted);
         break;
         
         case 'P' : print (A);
         break;
         
         case 'S' : sort (A, &amp;amp;sorted);
         break;
         
         
         case 'Z' : printf ("Goodbye!\n\n");
         break;
         
         case 'Q' : printf ("Query coming up!\n\n");
                    if ( sorted == 0 ) printf ("the array is not sorted!\n");
                    else printf ("the array is sorted!\n");
          break;
         
         default : printf ("\a\a Invalid selection!!!\n\n");    
      }
 
    }while ( selection != 'Z');
    
    system ("pause");
    return 0;
}
//----------------------------

char menuVersion1 ()
{
     char option;
     
     printf ("\n--------\nF-Fill the array \n");
     printf ("P-Print the array\n");
     printf ("S-Sort the array\n");
     printf ("Z-Exit\n");
     printf ("Enter your selection :");
     scanf(" %c", &amp;amp;option);

     return toupper(option);


}

//--------------------------------
void  menuVersion2 (char * option)
{
     
     
     printf ("\n--------\nF-Fill the array \n");
     printf ("P-Print the array\n");
     printf ("S-Sort the array\n");
     printf ("Q-Query the array\n");
     printf ("Z-Exit\n");
     printf ("Enter your selection :");
     scanf(" %c", option);

     *option = toupper(*option);
}
//---------------------------------
void fill ( int A [] , int * sorted)
{
   int walker;
   for (walker = 0 ; walker &amp;lt; SIZE ; walker ++)
   {   
      A[walker] = rand ()%999 + 1;    
   }
   *sorted = 0;
   
   printf ("ARRAY LOADED!!!\n");
     
}

//----------------------------------------
void print ( int A [])
{
   int walker;
   printf ("\nHere are the elements ...\n");
   for (walker = 0 ; walker &amp;lt; SIZE ; walker ++)
   {   
      printf ("%d\n", A[walker] );
   }
   
   printf ("\a ARRAY PRINTED!!!\n");
     
}
//------------------------
void sort ( int A[] , int * sorted )
{

   int i , j , temp ;
   *sorted = 1;
   
   for ( j= 0; j&amp;lt;SIZE ; j++)
   {
    for ( i=0; i&amp;lt;=SIZE-2 ; i++)
    {
       if ( A[i] &amp;gt; A[i+1])
       {
            temp = A[i];
            A[i] = A[i+1];
            A[i+1] = temp;
       }
    }
  }



}


&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/393261/393261/how-to-do-a-sequential-search-in-c/</guid>
      <pubDate>Fri, 03 Jul 2009 14:49:15 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Simple Sound from a C++ program?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/393216/393216/simple-sound-from-a-c++-program/</link>
      <description>For a course on musical acoustics, I've written a program that allows the user to draw a wave shape.  I'd like the user to be able to hear that wave shape.  The program is in C++, and the "shape" consists of 300 integer entries, so I'd like that file somehow to "loop" as it's converted to sound.&lt;br /&gt;
&lt;br /&gt;
The program uses OpenGL.  It's presently on a Dell (using Linux), though I'd like to be able to use it on a Mac (OSX) as well.&lt;br /&gt;
&lt;br /&gt;
Thanks for any help you can give.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/393216/393216/simple-sound-from-a-c++-program/</guid>
      <pubDate>Thu, 02 Jul 2009 14:51:09 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Buffer overflow c/c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/393213/393213/buffer-overflow-cc++/</link>
      <description>Hello,&lt;br /&gt;
how can I find a buffer overflow in C/C++.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
int x[10];&lt;br /&gt;
int y[5][5];&lt;br /&gt;
int z[5][5][2];&lt;br /&gt;
&lt;br /&gt;
x[12] = 0;&lt;br /&gt;
y[3][7] = 8;&lt;br /&gt;
z[2][6][1] = 8;&lt;br /&gt;
&lt;br /&gt;
   Thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/393213/393213/buffer-overflow-cc++/</guid>
      <pubDate>Thu, 02 Jul 2009 14:23:42 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Fuzzy Logic Pattern Matching</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/393144/393144/fuzzy-logic-pattern-matching/</link>
      <description>I am developing an application which at one point needs to do some pattern matching.  Specifically, I have 2 similar linear sets of data.  I want to match the points at which the data goes up and then down (a hump).  I want to find the best matches for the hump shapes in order to match up the data.  The hump may have a different number of values between the 2 sets of data.  For instance, data set A may have a hump consisting of 10 values from start to finish, but the corresponding hump in data set B may only have 8 values.&lt;br /&gt;
&lt;br /&gt;
I've done some research, and fuzzy logic seems to be the best way to do this, but I am not experienced enough with fuzzy logic theory to fully understand how to do this.  I've tried pattern matching using normal (crisp) programming, and it simply doesn't give good results in most cases.&lt;br /&gt;
&lt;br /&gt;
If anyone could give me advice as to how to set up the fuzzy inputs, maybe even some source code, I'd really appreciate it.&lt;br /&gt;
&lt;br /&gt;
Thanks!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/393144/393144/fuzzy-logic-pattern-matching/</guid>
      <pubDate>Wed, 01 Jul 2009 17:51:54 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>UDP Server. It won't bind()</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392969/392969/udp-server-it-wont-bind/</link>
      <description>Hello. I'm trying to make an UDP server which will do certain things on one's computer based on the messages received.&lt;br /&gt;
&lt;br /&gt;
That's how far i got:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#include "windows.h"
#include "winsock2.h"

int main()
{
    WSADATA wsaData;
    if(WSAStartup(0x0202, &amp;amp;wsaData))
    {
        MessageBox(NULL,"Call to WSAStartup() failed", "Error!", MB_ICONSTOP);
        WSACleanup();
        return 0;
    }
    else
    {
        if(wsaData.wVersion != 0x0202)
        {
            MessageBox(NULL,"Wrong socket version!", "Error!", MB_ICONSTOP);
            WSACleanup();
            return 0;
        }
    }

    sockaddr_in serverSockAddrIn;
    memset(&amp;amp;serverSockAddrIn, 0, sizeof(serverSockAddrIn));
    serverSockAddrIn.sin_family = AF_INET;
    serverSockAddrIn.sin_port = htons(14564);
    serverSockAddrIn.sin_addr.s_addr = htonl(INADDR_ANY);

    SOCKET serverSocket;
    serverSocket = (AF_INET, SOCK_DGRAM, IPPROTO_UDP);

    if(serverSocket == INVALID_SOCKET)
    {
        MessageBox(NULL, "Socket initialization failed!", "Error!", MB_ICONSTOP);
        WSACleanup();
        return 0;
    }

    if(bind(serverSocket,(sockaddr*)&amp;amp;serverSockAddrIn, sizeof(serverSockAddrIn)) == SOCKET_ERROR)
    {
        MessageBox(NULL, "Binding failed!", "Error!", MB_ICONSTOP);
        WSACleanup();
        return 0;
    }

    WSACleanup();
}

&lt;/pre&gt; &lt;br /&gt;
&lt;br /&gt;
I compiled the code just to test and see if there are any spelling errors and for my surprise o noticed that it won't bind(). I've checked MSDN and several examples. Everything seems to be fine according to those examples.&lt;br /&gt;
&lt;br /&gt;
Why do you think this is happening? I've checked the port i am bind(ing)() to and it's free.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392969/392969/udp-server-it-wont-bind/</guid>
      <pubDate>Sun, 28 Jun 2009 12:33:38 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>What is wrong with the following code</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392909/392909/what-is-wrong-with-the-following-code/</link>
      <description>template &amp;lt;class T&amp;gt; class TGrid&lt;br /&gt;
{&lt;br /&gt;
protected:&lt;br /&gt;
// T SubGrid[GRIDSIZE];&lt;br /&gt;
public:&lt;br /&gt;
void Intialize(void);&lt;br /&gt;
// void AddEnemy(unsigned char, unsigned char, unsigned char);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;class T&amp;gt; void TGrid&amp;lt;T&amp;gt;::Intialize()&lt;br /&gt;
{&lt;br /&gt;
unsigned short n;&lt;br /&gt;
for(n=0;n&amp;lt;GRIDSIZE;n++){}&lt;br /&gt;
// SubGrid[n].Intialize();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
No this isn't the whole program but this is the section Norton thinks is a virus. I am hoping that someone on here know because no one a norton does&lt;br /&gt;
&lt;br /&gt;
And no the answer isn't norton sucks I already know that and am switching I am just curious about why this harmless piece of code trigger a virus alert from norton&lt;br /&gt;
1 second ago - 4 days left to answer. &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392909/392909/what-is-wrong-with-the-following-code/</guid>
      <pubDate>Fri, 26 Jun 2009 09:23:39 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Question on templates?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392891/392891/question-on-templates/</link>
      <description>Ok I have the following code&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;class T&amp;gt; class TLinkList&lt;br /&gt;
{&lt;br /&gt;
  protected:&lt;br /&gt;
   TItem&amp;lt;T&amp;gt;  FHead;&lt;br /&gt;
   TItem&amp;lt;T&amp;gt; *FItem;&lt;br /&gt;
   unsigned short FCount;&lt;br /&gt;
   unsigned short FPos;&lt;br /&gt;
  public:&lt;br /&gt;
  void Intialize(void);&lt;br /&gt;
  void Add(T Data)&lt;br /&gt;
  {&lt;br /&gt;
	if(FCount == 0)&lt;br /&gt;
	{&lt;br /&gt;
	  FItem-&amp;gt;Cur = Data;&lt;br /&gt;
	  FItem-&amp;gt;Next = new TItem&amp;lt;T&amp;gt;;&lt;br /&gt;
	  FHead.Next = FItem;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
      FItem = FHead.Next;&lt;br /&gt;
	  while(FItem-&amp;gt;Next != NULL)&lt;br /&gt;
      Next();&lt;br /&gt;
	  FItem-&amp;gt;Cur = Data;&lt;br /&gt;
      FItem-&amp;gt;Next = new TItem&amp;lt;T&amp;gt;;&lt;br /&gt;
	}&lt;br /&gt;
    FCount += 1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  void Next()&lt;br /&gt;
  {&lt;br /&gt;
	FItem = FItem-&amp;gt;Next;&lt;br /&gt;
	FPos += 1;&lt;br /&gt;
&lt;br /&gt;
  }&lt;br /&gt;
  inline unsigned short Count(){return FCount;}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;class T&amp;gt; void TLinkList&amp;lt;T&amp;gt;::Intialize()&lt;br /&gt;
{&lt;br /&gt;
	FHead.Next = new TItem&amp;lt;T&amp;gt;;&lt;br /&gt;
	FItem = new TItem&amp;lt;T&amp;gt;;&lt;br /&gt;
	FCount = 0;&lt;br /&gt;
	FPos = 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
When all in the same file it compiles fine, But I want to be able to move the body of the functions to the .cpp file so the .h file isn't so cluttered(not mention is bad form.  problem is when I do that I get a liker error.  How do I get it to compile with the class defintions in the header file and the Body of the fuctions in the .cpp file?</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392891/392891/question-on-templates/</guid>
      <pubDate>Fri, 26 Jun 2009 05:28:39 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>cout problem on chinese zodiac program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392844/392844/cout-problem-on-chinese-zodiac-program/</link>
      <description>Hello. I'm making a Chinese zodiac program for fun, but regardless of what year I input I always get back "You were born in the year of the Dragon." &lt;br /&gt;
Thanks&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
	int year;     // four digit year&lt;br /&gt;
	cout &amp;lt;&amp;lt; "Enter your four digit birth year: ";&lt;br /&gt;
	cin &amp;gt;&amp;gt; year; &lt;br /&gt;
	if (year == 1976^1964) &lt;br /&gt;
	{cout &amp;lt;&amp;lt; "You were born in the year of the Dragon\n";}&lt;br /&gt;
	&lt;br /&gt;
	else if (year == 1981) &lt;br /&gt;
	{cout &amp;lt;&amp;lt; "Your were born in the year of the Rooster\n";}&lt;br /&gt;
	&lt;br /&gt;
	else if (year == 1982)&lt;br /&gt;
	{cout &amp;lt;&amp;lt; "Your were born in the year of the Dog\n";}&lt;br /&gt;
	&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392844/392844/cout-problem-on-chinese-zodiac-program/</guid>
      <pubDate>Thu, 25 Jun 2009 07:52:46 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>prefered C++ environment, Help needed</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392806/392806/prefered-c++-environment-help-needed/</link>
      <description>Hello,&lt;br /&gt;
&lt;br /&gt;
I have been programming in C/C++ and other languages in the past.&lt;br /&gt;
Borland C++, Windows Visual C++ console apps, Embedded controlers( Microchip MCC18), Visual Basic, others.&lt;br /&gt;
&lt;br /&gt;
Can someone please advise me of an appropriate starting platform to create Windows applications (on XP and Vista) in C/C++ without spending months of reading before my first Hello world program.&lt;br /&gt;
&lt;br /&gt;
I find most platform so criptic. MFC is non sense ! takes forever to learn.&lt;br /&gt;
&lt;br /&gt;
All I want to do is to create windows, place text and graphic, communicate with serial port or USB, etc ...&lt;br /&gt;
&lt;br /&gt;
Please avoid Microsoft tools. I am looking for open source, mainly.&lt;br /&gt;
&lt;br /&gt;
I tried FreeBasic, it is nice but I prefer C.&lt;br /&gt;
&lt;br /&gt;
I need a platform that won't take forever to learn.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Please help !&lt;br /&gt;
&lt;br /&gt;
Hans&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392806/392806/prefered-c++-environment-help-needed/</guid>
      <pubDate>Wed, 24 Jun 2009 17:06:17 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Can i more easy that program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392800/392800/can-i-more-easy-that-program/</link>
      <description>#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
	int b,c,d,e,f=0,g=0,h=1;&lt;br /&gt;
	char a[50];&lt;br /&gt;
	for (b=0; b&amp;lt;50; b++) {&lt;br /&gt;
		a&lt;strong&gt;=0;&lt;br /&gt;
	}&lt;br /&gt;
	printf("Enter a String : ");&lt;br /&gt;
	gets(a);&lt;br /&gt;
	for (c=0; c&amp;lt;50; c++) {&lt;br /&gt;
		if (a[c]==0) {&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	e=c;&lt;br /&gt;
	for (b=c; b&amp;gt;0; b--) {&lt;br /&gt;
		for (d=b; d&amp;gt;0; d--) {&lt;br /&gt;
			printf(" ");&lt;br /&gt;
		}&lt;br /&gt;
		for (d=0; d&amp;lt;=f; d++) {&lt;br /&gt;
			if (d==0||d==f) {&lt;br /&gt;
				printf("%c", a[g]);	&lt;br /&gt;
			}&lt;br /&gt;
			else if(b!=1){&lt;br /&gt;
				printf(" ");&lt;br /&gt;
			}&lt;br /&gt;
			if (b==1&amp;amp;&amp;amp;h==1) {&lt;br /&gt;
				printf(" ");&lt;br /&gt;
			}&lt;br /&gt;
			if (b==1) {&lt;br /&gt;
				if(h==c){&lt;br /&gt;
					break;&lt;br /&gt;
				}&lt;br /&gt;
				printf("%c ", a[h]);&lt;br /&gt;
				h++;&lt;br /&gt;
			}	&lt;br /&gt;
		}&lt;br /&gt;
		g++;&lt;br /&gt;
		f+=2;&lt;br /&gt;
		printf("\n\n");&lt;br /&gt;
	}&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;/strong&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392800/392800/can-i-more-easy-that-program/</guid>
      <pubDate>Wed, 24 Jun 2009 15:53:04 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>problem with the refresh()</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392768/392768/problem-with-the-refresh/</link>
      <description>I am new to encurses.&lt;br /&gt;
I am trying to get a multicast message and print it on to the screen using ncurses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt; 
initscr();				
row = 0;
col = 0;
main_pid = getpid();
refresh();

for (;;) //Run forever
{          
    /* clear the receive buffers &amp;amp; structs */
    memset(recv_str, 0, sizeof(recv_str));
    from_len = sizeof(from_addr);
    memset(&amp;amp;from_addr, 0, from_len);

    /* block waiting to receive a packet */
    if ((recv_len = recvfrom(sock, recv_str, MAX_LEN, 0,(struct sockaddr*)&amp;amp;from_addr, &amp;amp;from_len)) &amp;lt; 0) 
    {
      perror("recvfrom() failed");
      exit(1);
    }
	strcpy(str,recv_str);
	
    /* output received string */
    move(row,col);
    printw("\nReceived %d bytes from %s: %s ", recv_len, 
           inet_ntoa(from_addr.sin_addr), str);
	
    refresh();
    row++;
	
    signal(SIGINT, should_i_stop);

}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
The message is printed in the next line. But every time a new message comes it prints only it and erases all the previous ones. &lt;br /&gt;
How to over come this?&lt;br /&gt;
How can I only update the new message keeping the previous messages unerased?&lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
Spatika&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392768/392768/problem-with-the-refresh/</guid>
      <pubDate>Wed, 24 Jun 2009 04:43:30 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>ANN: Unit testing framework cfix 1.4 released</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392762/392762/ann-unit-testing-framework-cfix-14-released/</link>
      <description>Hi,&lt;br /&gt;
&lt;br /&gt;
a new version of cfix, the open source unit testing framework for&lt;br /&gt;
user and kernel mode C and C++, has been released. cfix 1.4, in addition to the existing feature of allowing test runs to be restricted to specific fixtures, now also allows single testcases to be run in isolation, which can be a great aid in debugging. Besides other minor fixes, the cfix API has been slightly enhanced and cfix now degrades more gracefully in case of dbghelp-issues.&lt;br /&gt;
&lt;br /&gt;
Updated cfix binaries and source code are available on:&lt;br /&gt;
 &lt;a href="http://www.cfix-testing.org/"&gt;http://www.cfix-testing.org/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
As a major step forward, *cfix studio* has now entered public beta. cfix studio, built on top of cfix 1.4, is an *AddIn for Visual Studio&lt;br /&gt;
2005/2008* that adds C/C++ unit testing capabilities to the IDE --&lt;br /&gt;
including debugger integration, appropriate tool windows and built-in&lt;br /&gt;
support for dealing with multiple architectures (32/64 bit).&lt;br /&gt;
&lt;br /&gt;
Check out the free beta release on&lt;br /&gt;
 &lt;a href="http://www.cfix-studio.com/unit-testing-framework/download.html"&gt;http://www.cfix-studio.com/unit-testing-framework/download.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Tutorials are available here:&lt;br /&gt;
 &lt;a href="http://www.cfix-studio.com/visual-studio-addin/doc/TutorialUserVsCc.html"&gt;http://www.cfix-studio.com/visual-studio-addin/doc/TutorialUserVsCc.html&lt;/a&gt;&lt;br /&gt;
 &lt;a href="http://www.cfix-testing.org/doc/TutorialUserVsCc.html"&gt;http://www.cfix-testing.org/doc/TutorialUserVsCc.html&lt;/a&gt; (User C++)&lt;br /&gt;
 &lt;a href="http://www.cfix-testing.org/doc/TutorialUserVs.html"&gt;http://www.cfix-testing.org/doc/TutorialUserVs.html&lt;/a&gt; (User C)&lt;br /&gt;
 &lt;a href="http://www.cfix-testing.org/doc/TutorialKernelWdk.html"&gt;http://www.cfix-testing.org/doc/TutorialKernelWdk.html&lt;/a&gt; (Kernel C)&lt;br /&gt;
&lt;br /&gt;
As always, all kind of feedback is welcome!&lt;br /&gt;
&lt;br /&gt;
--JP</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392762/392762/ann-unit-testing-framework-cfix-14-released/</guid>
      <pubDate>Wed, 24 Jun 2009 02:47:25 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>create a new ATL project with exsisting IDL</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392713/392713/create-a-new-atl-project-with-exsisting-idl/</link>
      <description>I have one existing idl file(Add.idl) where the interface and the library is look like the following&lt;br /&gt;
&lt;br /&gt;
interface IAdd:IDispatch&lt;br /&gt;
{&lt;br /&gt;
         [id(1), AddNumber("Add two number")]&lt;br /&gt;
}&lt;br /&gt;
library ADDLib&lt;br /&gt;
{&lt;br /&gt;
 importlib("stdole32.tlb");&lt;br /&gt;
 importlib("stdole2.tlb");&lt;br /&gt;
&lt;br /&gt;
 [&lt;br /&gt;
  uuid(339171FF-A6E7-433F-A314-FF740F53FE56),&lt;br /&gt;
  helpstring("Add Class")&lt;br /&gt;
 ]&lt;br /&gt;
 coclass Add {&lt;br /&gt;
  [default] interface IAdd;&lt;br /&gt;
 };&lt;br /&gt;
};&lt;br /&gt;
Now I need to create one new ATL project which will import this file(Add.idl) and my interface will be derived from IAdd interface.&lt;br /&gt;
Then I will have to implement the AddNumber() method described in IAdd interface along with some new methods that will be present &lt;br /&gt;
in the newly implemented interface.&lt;br /&gt;
So,after implementation my idl file should look like this&lt;br /&gt;
&lt;br /&gt;
import "Add.idl";&lt;br /&gt;
interface Isample:IAdd&lt;br /&gt;
{&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
Can any one tell me the steps how to implement this in VS2008.&lt;br /&gt;
I am very new to this , please help me..&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392713/392713/create-a-new-atl-project-with-exsisting-idl/</guid>
      <pubDate>Tue, 23 Jun 2009 02:13:33 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Voice Enabled Home Automation</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392666/392666/voice-enabled-home-automation/</link>
      <description>Dear all Expert,&lt;br /&gt;
&lt;br /&gt;
I am a Electrical student working on a project of Voice Enabled Home Automation. As this is a school project, my professor therefore disallow me to use any existing software/hardware readily available in the market for Home Automation.&lt;br /&gt;
&lt;br /&gt;
I therefore had to start everything from scrape. Regarding the Hardware side, i will use a RF600D/E chip to control the Home applicances (e.g. lighting switch, power point, curtain drawer)&lt;br /&gt;
&lt;br /&gt;
As for the software side, I therefore need the help of your expertist. I need to write a C++ program using Microsoft Speech SDK 5.1 to control my RF chipset preferably using the computer Parallel port (no other circuit needed to interface to my RF chipset).&lt;br /&gt;
&lt;br /&gt;
E.g. When i voice out "Turn On Living Room Light", Parallel port pin 1 will turn on and off (Just a 50ms to 100ms of on time will do). The parallel port will be connected to my RF chipset input control which will in turns control my RF switch at remote end.&lt;br /&gt;
&lt;br /&gt;
I am seeking for help to start the source code writing for my program as i had limited knowledge to software programming. Does anyone has source code written for Voice control using SDK 5.1 that control the parallel port? Can anyone pls provide me a sample code to start with? Thanks a lot for anyone help. Have a nice day ahead. &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392666/392666/voice-enabled-home-automation/</guid>
      <pubDate>Mon, 22 Jun 2009 06:33:23 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>What's wrong with this program?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392659/392659/whats-wrong-with-this-program/</link>
      <description>It has to check if a sequence is accepted by pushdown automata:&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;conio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;alloc.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
typedef struct&lt;br /&gt;
    {&lt;br /&gt;
	char st;    // starea in care trece automatul&lt;br /&gt;
	char *sir;  // sirul de simboluri cu care se inlocuieste&lt;br /&gt;
		      // simbolul din varful stivei&lt;br /&gt;
    } tip_delta; // o vom numi varianta&lt;br /&gt;
&lt;br /&gt;
tip_delta *delta[15][10][10]; // functia de tranzitie&lt;br /&gt;
// deoarece automatul push down este nedeterminist fiecare     // element al tabloului delta  este o adresa la care se vor    // memora dinamic variantele posibile&lt;br /&gt;
&lt;br /&gt;
char Q[15]; // multimea starilor automatului&lt;br /&gt;
char S[10]; // multimea simbolurilor alfabetului de intrare&lt;br /&gt;
char Z[10]; // multimea simbolurilor alfabetului stivei&lt;br /&gt;
char F[15]; // multimea starilor finale ale automatului;&lt;br /&gt;
	       // este folosita doar daca criteriul de acceptare&lt;br /&gt;
	       // este cel al starii finale&lt;br /&gt;
char secv[50]; // secventa citita de pe banda de intrare&lt;br /&gt;
char crt; // criteriul de acceptare&lt;br /&gt;
	  // crt='v' ( stiva vida)&lt;br /&gt;
	  // crt='f' ( stare finala)&lt;br /&gt;
char stiva[50]; // memoria stiva&lt;br /&gt;
&lt;br /&gt;
int este(char x,char M[])&lt;br /&gt;
{&lt;br /&gt;
 // returneaza pozitia simbolului x in multimea M,&lt;br /&gt;
 // sau  1 daca x nu apartine lui M&lt;br /&gt;
  int i;&lt;br /&gt;
  for(i=0;M[i];i++)&lt;br /&gt;
      if(M[i]==x) return i;&lt;br /&gt;
  return( 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void citeste(char M[],char x)&lt;br /&gt;
{&lt;br /&gt;
  char *mesaj;&lt;br /&gt;
  switch(x)&lt;br /&gt;
  {&lt;br /&gt;
   case 's':&lt;br /&gt;
	mesaj="simbolurilor alfabetului de intrare";&lt;br /&gt;
	break;&lt;br /&gt;
   case 'q':&lt;br /&gt;
	mesaj="starilor (prima stare este starea initiala)\n";&lt;br /&gt;
	break;&lt;br /&gt;
   case 'f':&lt;br /&gt;
	mesaj="starilor finale";&lt;br /&gt;
	break;&lt;br /&gt;
   case 'p':&lt;br /&gt;
	mesaj="simbolurilor alfabetului memoriei stiva:";&lt;br /&gt;
	strcat(mesaj,"\n(primul simbol este simbolul initial al stivei)");&lt;br /&gt;
  }&lt;br /&gt;
  printf("\nDati multimea %s: ", mesaj);&lt;br /&gt;
  gets(M);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
void citdelta()&lt;br /&gt;
{ int i,j,k,l;&lt;br /&gt;
  tip_delta *pd;&lt;br /&gt;
  char sir1[50],*s,*s1;&lt;br /&gt;
  printf("\n exemplu pentru furnizarea functiei delta\n");&lt;br /&gt;
  printf("  delta[p,0,Z]=(p,&amp;amp;),(q,AA),(p,AZ)  \n\n");&lt;br /&gt;
  for(i=0;Q[i];i++)&lt;br /&gt;
   for(j=0;S[j];j++)&lt;br /&gt;
    for(k=0;Z[k];k++)&lt;br /&gt;
      {&lt;br /&gt;
       printf("\n delta[%c,%c,%c]=",Q[i],S[j],Z[k]);&lt;br /&gt;
       fflush(stdin);&lt;br /&gt;
       gets(sir1);&lt;br /&gt;
       if(strlen(sir1)==0)&lt;br /&gt;
       // nu e definita functia pentru tripletul Q[i],S[j],Z[k]&lt;br /&gt;
	       {delta[i][j][k]=NULL; continue;}&lt;br /&gt;
       s=sir1;&lt;br /&gt;
       l=0;&lt;br /&gt;
       // se numara variantele  citite  si se aloca dinamic&lt;br /&gt;
       // zona necesara pentru memorarea lor; ultima varianta&lt;br /&gt;
       // introdusa va fi o varianta fictiva care va contine&lt;br /&gt;
       // componenta sir=NULL si este utilizata pentru a&lt;br /&gt;
       // depista sfarsitul variantelor&lt;br /&gt;
       while(s=strchr(s,'('))&lt;br /&gt;
	     {l++;s++;}&lt;br /&gt;
       pd=delta[i][j][k]=&lt;br /&gt;
                    (tip_delta *)malloc((l+1)*sizeof(tip_delta));&lt;br /&gt;
       s=sir1;&lt;br /&gt;
       while(s=strchr(s,'('))&lt;br /&gt;
	 {&lt;br /&gt;
	  pd &amp;gt;st=*(s+1);&lt;br /&gt;
	  s1=s+3;&lt;br /&gt;
	  s=strchr(s1,')');&lt;br /&gt;
	  *s='\0';&lt;br /&gt;
	  pd &amp;gt;sir=(char *)malloc(strlen(s1)+1);&lt;br /&gt;
	  strcpy(pd &amp;gt;sir,s1);&lt;br /&gt;
	  s=s+1;&lt;br /&gt;
	  pd++;&lt;br /&gt;
	 }&lt;br /&gt;
      pd &amp;gt;sir=NULL;  // completarea variantei fictive&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int push(char *x,int vs)&lt;br /&gt;
{&lt;br /&gt;
 // inlocuieste simbolul din varful stivei cu sirul&lt;br /&gt;
 // de caractere de la adresa x&lt;br /&gt;
 // se actualizeaza varful stivei : vs&lt;br /&gt;
 char *p;&lt;br /&gt;
 vs  ;&lt;br /&gt;
 if(*x!='&amp;amp;')&lt;br /&gt;
    {&lt;br /&gt;
     for(p=x;*p;p++);&lt;br /&gt;
     for(p  ;p&amp;gt;=x;p  ) stiva[vs++]=*p;&lt;br /&gt;
    }&lt;br /&gt;
return vs;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int accept(char q,int i,int vs)&lt;br /&gt;
{&lt;br /&gt;
 // functia returneaza valoarea 1 daca secventa este&lt;br /&gt;
 // acceptata de automat si  1 in caz contrar&lt;br /&gt;
 // se modeleaza metoda backtracking recursiv pentru&lt;br /&gt;
 // gasirea solutiei&lt;br /&gt;
  char simb[2];&lt;br /&gt;
  int j,n,vf,k,l,m;&lt;br /&gt;
  tip_delta *p;&lt;br /&gt;
  n=0;&lt;br /&gt;
  if(crt=='v')   // criteriul stivei vide&lt;br /&gt;
    {if(secv[i]=='\0')&lt;br /&gt;
	 if(vs==0) return(1);&lt;br /&gt;
	    else n=1;&lt;br /&gt;
    }&lt;br /&gt;
   else         // criteriul starii finale&lt;br /&gt;
    {if(secv[i]=='\0')&lt;br /&gt;
	 if(este(q,F)!= 1) return(1);&lt;br /&gt;
	      else n=1;&lt;br /&gt;
    }&lt;br /&gt;
  simb[0]=secv[i];&lt;br /&gt;
  simb[1]='&amp;amp;';&lt;br /&gt;
  vf=vs;&lt;br /&gt;
  for(j=n;j&amp;lt;2;j++)&lt;br /&gt;
    {&lt;br /&gt;
    // se incearca cele doua posibilitati:&lt;br /&gt;
    //  daca simb[j]=secv[i] se incearca avansarea pe banda&lt;br /&gt;
    //       de intrare cu simbolul secv[i]&lt;br /&gt;
    //  daca simb[j]='&amp;amp;' se incearca o epsilon tranzitie&lt;br /&gt;
     if((k=este(q,Q))== 1)break;&lt;br /&gt;
     if((l=este(simb[j],S))== 1) {j++;continue;}&lt;br /&gt;
     if(vf&amp;lt;1) break;&lt;br /&gt;
     if((m=este(stiva[vf 1],Z))== 1) break;&lt;br /&gt;
     p=delta[k][l][m];&lt;br /&gt;
     for(;p &amp;amp;&amp;amp; p &amp;gt;sir;p++) // se parcurg toate variantele&lt;br /&gt;
	 {&lt;br /&gt;
	  vs=vf;&lt;br /&gt;
	  vs=push(p &amp;gt;sir,vs);&lt;br /&gt;
	  if(accept(p &amp;gt;st,i+1 j,vs)!= 1) return(1);&lt;br /&gt;
	 }&lt;br /&gt;
    }&lt;br /&gt;
  return( 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(void)&lt;br /&gt;
{&lt;br /&gt;
  int ind,i,j,k;&lt;br /&gt;
  int vs; // virf stiva ( vs=0 indica stiva vida )&lt;br /&gt;
  char q;&lt;br /&gt;
  clrscr();&lt;br /&gt;
  printf("  Simularea functionarii unui automat push down\        nedeterminist");&lt;br /&gt;
  citeste(Q,'q'); // citire stari automat&lt;br /&gt;
  citeste(S,'s'); // citire alfabet de intrare&lt;br /&gt;
  strcat(S,"&amp;amp;");  // se adauga la alfabetul de intrare&lt;br /&gt;
	             // epsilon simbolizat prin &amp;amp;&lt;br /&gt;
  citeste(Z,'p'); // citire alfabet memorie stiva&lt;br /&gt;
  printf("\n Dati criteriul de acceptare\n");&lt;br /&gt;
  printf("   stiva vida(v) ,stare finala (f) :");&lt;br /&gt;
  if((crt=tolower(getche()))=='f')&lt;br /&gt;
       citeste(F,'f'); // citire stari finale&lt;br /&gt;
  printf(" \n\n Functia de tranzitie delta:");&lt;br /&gt;
  printf("\n   (simbolul &amp;amp; reprezinta epsilon)");&lt;br /&gt;
  printf("\n   (daca delta nu e definita pentru un triplet\       tastati ENTER)\n");&lt;br /&gt;
  citdelta();&lt;br /&gt;
  printf("\n\n Doriti sa verificati secventa?(d/n):");&lt;br /&gt;
  while(tolower(getche())!='n')&lt;br /&gt;
  {&lt;br /&gt;
   printf("\n Dati secventa (pt secventa vida dati ENTER):\n");&lt;br /&gt;
   gets(secv);  // citirea secventei de pe banda de intrare&lt;br /&gt;
   stiva[0]=Z[0]; // initializarea stivei cu simbolul&lt;br /&gt;
	             // initial al stivei&lt;br /&gt;
   vs=1; // arata pozitia pe care se poate adauga un nou&lt;br /&gt;
	 // element in stiva; vs=0 indica stiva vida&lt;br /&gt;
	 // elementul din varful stivei este stiva[vs 1]&lt;br /&gt;
   if(accept(Q[0],0,vs)!= 1)&lt;br /&gt;
	     printf("\n  secventa este acceptata");&lt;br /&gt;
	  else&lt;br /&gt;
	     printf("\n secventa nu este acceptata");&lt;br /&gt;
    printf("\n\n Doriti sa verificati secventa?(d/n):");&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392659/392659/whats-wrong-with-this-program/</guid>
      <pubDate>Mon, 22 Jun 2009 05:58:20 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>PushDown Automata(PDA) source code?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392654/392654/pushdown-automatapda-source-code/</link>
      <description>Does anyone have a Pushdown automata source code, or algorithm? or do you know where i can find it? &lt;br /&gt;
Thanks.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392654/392654/pushdown-automatapda-source-code/</guid>
      <pubDate>Mon, 22 Jun 2009 05:15:09 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Free C/C++ eBooks download for you</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392622/392622/free-cc++-ebooks-download-for-you/</link>
      <description>Here you can free download Free C/C++ eBooks&lt;br /&gt;
&lt;a href="http://ebookhouse.org/category/programming/cc/"&gt;http://ebookhouse.org/category/programming/cc/&lt;/a&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392622/392622/free-cc++-ebooks-download-for-you/</guid>
      <pubDate>Sun, 21 Jun 2009 19:13:33 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Reverse string</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392612/392612/reverse-string/</link>
      <description>hai all,&lt;br /&gt;
&lt;br /&gt;
        may any one know how to find the length of the string without using strlen functions and temporary variable.........&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392612/392612/reverse-string/</guid>
      <pubDate>Sun, 21 Jun 2009 05:23:07 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Rewriteing VB program in C - Serial port handling</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392573/392573/rewriteing-vb-program-in-c---serial-port-handling/</link>
      <description>Hi!&lt;br /&gt;
&lt;br /&gt;
I built this PC thermometer: &lt;a href="http://www.riccibitti.com/pc_therm.htm"&gt;http://www.riccibitti.com/pc_therm.htm&lt;/a&gt;&lt;br /&gt;
It works fine with it's windows application, but I want to write an app for Linux in C based on the original VB code. &lt;a href="http://home.sinuslink.hu/stuff/thermosoft/"&gt;Here's&lt;/a&gt; my work, and the original VB code. Plz someone chek my C program, and tell me if he/she found any difference betweenthe two app.&lt;br /&gt;
&lt;br /&gt;
Thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392573/392573/rewriteing-vb-program-in-c---serial-port-handling/</guid>
      <pubDate>Sat, 20 Jun 2009 05:12:35 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Dijkstra Algorithm</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392535/392535/dijkstra-algorithm/</link>
      <description>&lt;span style="font-size: medium;"&gt;hi&lt;br /&gt;
i have a question how i can know the second shortest path by dijkstra algorithm &lt;/span&gt;&lt;span style="color: Blue;"&gt;&lt;/span&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392535/392535/dijkstra-algorithm/</guid>
      <pubDate>Fri, 19 Jun 2009 04:49:34 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Calculating Entropy of a file and coding it using Hamming</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392528/392528/calculating-entropy-of-a-file-and-coding-it-using-hamming/</link>
      <description>Hello there!&lt;br /&gt;
&lt;br /&gt;
I am trying to solve a problem for a project i took and i am in the final&lt;br /&gt;
&lt;br /&gt;
part of it...(view below for my until now code)&lt;br /&gt;
&lt;br /&gt;
Well the aim is to calculate the entropy of a file and then to use&lt;br /&gt;
&lt;br /&gt;
Hamming to code it. I managed to make both parts based on what I learned&lt;br /&gt;
&lt;br /&gt;
from the class and read in the book. (Please if you are familiar with the&lt;br /&gt;
&lt;br /&gt;
object tell me if it is correct )&lt;br /&gt;
&lt;br /&gt;
So, my problem is that I am not able to merge those two parts below (you&lt;br /&gt;
&lt;br /&gt;
dont need to read the theory for it).. like finding the entropy and then&lt;br /&gt;
&lt;br /&gt;
continue for the coding of that file.&lt;br /&gt;
&lt;br /&gt;
Any help, advice, anything is appreciate.&lt;br /&gt;
Thank you!&lt;br /&gt;
&lt;br /&gt;
Entropy Calculation&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#include "BufferedNode.h"
#include "Buffer.h"
#include "Vector.h"
#include &amp;lt;strstream&amp;gt;
#include &amp;lt;math.h&amp;gt;

#ifdef HAVE_VALUES_H
#include &amp;lt;values.h&amp;gt;
#endif

#ifdef HAVE_FLOAT_H
#include &amp;lt;float.h&amp;gt;
#endif

class Entropy;

DECLARE_NODE(Entropy)
/*Node
 *
 * @name Entropy
 * @category DSP:Misc
 * @description Calculates the entropy of a vector
 *
 * @input_name INPUT
 * @input_type Vector&amp;lt;float&amp;gt;
 * @input_description Input vector
 *
 * @output_name OUTPUT
 * @output_type Vector&amp;lt;float&amp;gt;
 * @output_description Entropy value (vector of 1)
 *
END*/


class Entropy : public BufferedNode {
   
   int inputID;
   int outputID;

public:
   Entropy(string nodeName, ParameterSet params)
      : BufferedNode(nodeName, params)

   {
      inputID = addInput("INPUT");
      outputID = addOutput("OUTPUT");
   }

   void calculate(int output_id, int count, Buffer &amp;amp;out)
   {
      ObjectRef inputValue = getInput(inputID, count);

      const Vector&amp;lt;float&amp;gt; &amp;amp;in = object_cast&amp;lt;Vector&amp;lt;float&amp;gt; &amp;gt; (inputValue);
      int inputLength = in.size();

      Vector&amp;lt;float&amp;gt; &amp;amp;output = *Vector&amp;lt;float&amp;gt;::alloc(1);
      out[count] = &amp;amp;output;

      float s2=0;
      float entr=0;
      for (int i=0;i&amp;lt;inputLength;i++)
      {
         s2+=in[i]*in[i];
      }
      s2 = 1/s2;

      for (int i=0;i&amp;lt;inputLength;i++)
      {
	 if (in[i] != 0)
	    entr -= s2*in[i]*in[i] * log(s2*in[i]*in[i]);
      }
      //cout &amp;lt;&amp;lt; entr &amp;lt;&amp;lt; endl;
      output[0] = entr;
   }

};&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Hamming coding:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#include&amp;lt;iostream.h&amp;gt;   
#include&amp;lt;math.h&amp;gt;   
void hanming()   
{   
int i,n,k=2;   
int h[20];   
for(i=0;i&amp;lt;20;i++)h[i]=0;   
cout&amp;lt;&amp;lt;"bla bla"&amp;lt;&amp;lt;endl; cin=""&amp;gt;&amp;gt;n;   
while(pow(2,k)&amp;lt;n+k+1)k++; cout=""&amp;gt;&amp;lt;&amp;lt;"bla bla"&amp;lt;&amp;lt;endl; for(i="1;i&amp;lt;=n+k;i++){" if(i!="1&amp;amp;&amp;amp;i!=2&amp;amp;&amp;amp;i!=4&amp;amp;&amp;amp;i!=8)cin"&amp;gt;&amp;gt;h[i];   
}   
h[1]=(h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;   
h[2]=(h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2;   
h[4]=(h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2;   
h[8]=(h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])%2;   
for(i=1;i&amp;lt;=n+k;i++)cout&amp;lt;&amp;lt;h[i]; jiaoyan(int="" a[],int="" n)="" {="" i,p1,p2,p4,p8,m;="" int="" h[20];="" for(i="0;i&amp;lt;n;i++)h

[i+1]=a[i];" k="2;" p1="(h[1]+h[3])%2;" p2="(h[2]+h[3])%2;" m="2*p2+p1;" return="" m;="" }="" if(n="=3){"&amp;gt;=5&amp;amp;&amp;amp;n&amp;lt;=7){   
// k=3;   
p1=(h[1]+h[3]+h[5]+h[7])%2;   
p2=(h[2]+h[3]+h[6]+h[7])%2;   
p4=(h[4]+h[5]+h[6]+h[7])%2;   
m=4*p4+2*p2+p1;   
return m;   
}   
if(n&amp;gt;=9&amp;amp;&amp;amp;n&amp;lt;=15){   
//k=4;   
p1=(h[1]+h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;   
p2=(h[2]+h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2
;   
p4=(h[4]+h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2
;   
p8=(h[8]+h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])
%2;   
m=8*p8+4*p4+2*p2+p1;   
return m;   
}   
else{   
cout&amp;lt;&amp;lt;"bla bla"&amp;lt;&amp;lt;endl; return="" -1;="" }="" ����="" void="" main()="" {="" hanming();="" coco;="" int="" i,n,m,h[20];="" 

cout=""&amp;gt;&amp;lt;&amp;lt;endl; cout=""&amp;gt;&amp;lt;&amp;lt;"bla bla"&amp;lt;&amp;lt;endl; cin=""&amp;gt;&amp;gt;n;   
cout&amp;lt;&amp;lt;"bla bla"&amp;lt;&amp;lt;endl; for(i="0;i&amp;lt;n;i++)cin"&amp;gt;&amp;gt;h[i];   
m=jiaoyan(h,n);   
if(m==0)cout&amp;lt;&amp;lt;"bla bla"&amp;lt;&amp;lt;endl; if(m!="0)cout&amp;lt;&amp;lt;"bla bla"&amp;lt;&amp;lt;m;" cout=""&amp;gt;&amp;lt;&amp;lt;endl; cin=""&amp;gt;&amp;gt;coco;   
}&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392528/392528/calculating-entropy-of-a-file-and-coding-it-using-hamming/</guid>
      <pubDate>Fri, 19 Jun 2009 02:51:51 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>How to put video on iPod/iPhone/PSP/Zune/Zen/Sansa Fuze……</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392527/392527/how-to-put-video-on-ipodiphonepspzunezensansa-fuze/</link>
      <description>This guide is shared to help people put any video on their portable devices.&lt;br /&gt;
&lt;br /&gt;
Most devices only accept the following commen video formats:&lt;br /&gt;
&lt;strong&gt;iPod/iPhone:&lt;/strong&gt; H.264 (up to 320*240, 768kbps, 30fps), MPEG-4 (up to 480*480, 2500kbps, 30fps).&lt;br /&gt;
&lt;strong&gt;Zune: &lt;/strong&gt;WMV, MPEG-4, H.264(30fps).&lt;br /&gt;
&lt;strong&gt;Creative Zen: &lt;/strong&gt;AVI.&lt;br /&gt;
&lt;strong&gt;Sansa: &lt;/strong&gt;MPEG-4, MP4.&lt;br /&gt;
&lt;br /&gt;
In order to put some unusual video on your portable devices you need a professional &lt;strong&gt;&lt;a href="http://www.4easysoft.com/total-video-converter.html"&gt;Video Converter &lt;/a&gt; &lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;4Easysoft Total video converter &lt;/strong&gt;can convert video between almost all video formats.&lt;br /&gt;
&lt;strong&gt;Input Video Formats:&lt;/strong&gt; WMV, MP4, MOV, M4V, AVI, FLV, 3GP, 3G2, MPG, VOB, MPEG, MPG, ASF, MOD, MKV,RM,TOD, MPV, TS.&lt;br /&gt;
&lt;strong&gt;Output video formats:&lt;/strong&gt;MP4, MOV, M4V, VOB, XviD, AVI, FLV, 3GP, 3G2, MPG, ASF, MKV, RM. H.264.MPEG-4, WMV.&lt;br /&gt;
So, with this powerful software can be used as &lt;a href="http://www.4easysoft.com/vob-converter.html"&gt;VOB Converter&lt;/a&gt;, &lt;a href="http://www.4easysoft.com/palm-video-converter.html"&gt;Palm Video Converter&lt;/a&gt;, &lt;a href="http://www.4easysoft.com/3gp-video-converter.html"&gt;3GP Video Converter&lt;/a&gt;, &lt;a href="http://www.4easysoft.com/quicktime-video-converter.html"&gt;Quicktime Video Converter&lt;/a&gt;, etc.&lt;br /&gt;
&lt;br /&gt;
The following is about how to use video converter to convert almost any video formats to most portable devices supported video.&lt;br /&gt;
&lt;strong&gt;Step 0:&lt;/strong&gt; Download and install &lt;a href="http://www.4easysoft.com/download/total-video-converter.exe"&gt;4Easysoft Total Video Converter&lt;/a&gt;&lt;br /&gt;
&lt;strong&gt;Step 1:&lt;/strong&gt; Run it and click the “Add File” button to load your video.&lt;br /&gt;
&lt;strong&gt;Step 2:&lt;/strong&gt; Select the output video format from the profile drop-download list.&lt;br /&gt;
The profile including video for almost any portable devices such as iPod, iPhone, Archos, iRiver, PSP, Zune. Creative Zen, Nokia Serials, Palm, and so on.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.4easysoft.com/guide/video-converter/start.jpg" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 3:&lt;/strong&gt;Edit your video.&lt;br /&gt;
You can use the powerful editing function to edit your video.&lt;br /&gt;
&lt;strong&gt;Trim&lt;/strong&gt;: You can use this function to cut any clip of your video.&lt;br /&gt;
Click the “Trim” and a dialogue-box pops up. You can drag the slide-bar to the position you want.&lt;br /&gt;
You can also set the Start time and the End time to trim your video.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.4easysoft.com/guide/video-converter/trim.JPG" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Crop:&lt;/strong&gt; You can remove the black edges around your movie video and customize the size of video play region as you wish. Click “Crop” to open the Trim window. Select a crop mode in the Crop Mode drop-down list and click OK to save the crop. &lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.4easysoft.com/guide/video-converter/crop.JPG" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Preferences&lt;/strong&gt;: By clicking the “Preference” button you can select the output destination, the Snapshot foler, the format of the snapshot image. You can also choose to shut down your computer or do nothing after your conversion. You can also select the CPU usage.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.4easysoft.com/guide/video-converter/preference.JPG" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Merge&lt;/strong&gt;: You can use this function to merge several videos into one.&lt;br /&gt;
&lt;strong&gt;Snapshot&lt;/strong&gt;: You can use this function to capture your favorite image.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 4:&lt;/strong&gt; Click the “Start” button to start your conversion and in a short while it will be finished.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392527/392527/how-to-put-video-on-ipodiphonepspzunezensansa-fuze/</guid>
      <pubDate>Fri, 19 Jun 2009 02:11:59 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>C++ reading line problem  file</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392420/392420/c++-reading-line-problem--file/</link>
      <description>hi plz help. Trying since 1 week.&lt;br /&gt;
&lt;br /&gt;
acwl1 line we&lt;br /&gt;
james line rx&lt;br /&gt;
sijith fff xw&lt;br /&gt;
nisha nnn w&lt;br /&gt;
/sijith line r &lt;br /&gt;
/Arjun line w &lt;br /&gt;
vineeth line r&lt;br /&gt;
acls2 faculty x&lt;br /&gt;
arrr line2 w&lt;br /&gt;
Rahul line3 wx &lt;br /&gt;
Arjun line1 m&lt;br /&gt;
/Tom line wr&lt;br /&gt;
ac01l2 lineN w&lt;br /&gt;
aclM1 line1 rw&lt;br /&gt;
Ram line3 x&lt;br /&gt;
acalM line2 rx&lt;br /&gt;
acblM line3 &lt;br /&gt;
/jaffer line m &lt;br /&gt;
Ram line3 x&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here the line starting with / is command and others is arguments.&lt;br /&gt;
if any commands last word matches any letters of arguments last word it have to &lt;br /&gt;
print that argument(have to print only the first matching).&lt;br /&gt;
if one command preceeds other command then it have to check the same argumnets list above&lt;br /&gt;
Here "Arjun line w" matches "sijith fff xw" so  it have to output that argument(not nisha nnn w)&lt;br /&gt;
&lt;br /&gt;
eg:&lt;br /&gt;
" /sijith line r " matches "james line rx"&lt;br /&gt;
&lt;br /&gt;
we have to output james line rw&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if any command preceeds argument then it have to continue upto next command and check&lt;br /&gt;
the matching arguments inbetween two commands&lt;br /&gt;
eg:&lt;br /&gt;
Here /Arjun is preceeds by argument "vineeth line r" so continue upto command "/Tom line wr" and &lt;br /&gt;
check argument between Arjun and Tom and prints arrr line2 w &lt;br /&gt;
&lt;br /&gt;
Every time have to check arguments inbetween commands&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392420/392420/c++-reading-line-problem--file/</guid>
      <pubDate>Tue, 16 Jun 2009 22:35:32 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Using fstream.get in UNICODE...</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/392376/392376/using-fstreamget-in-unicode/</link>
      <description>Alright, I simply want verification that I am attempting to read in a string properly.  You see, I am writing an object that will read in binary data that was written by an old ANSI program in DOS.  The object compiles with no warnings or errors, but I may not be doing this correctly.  This object is UNICODE and as such, uses "wchar_t" instead of "char".  The old program wrote in a 14-character array followed by an integer value.  Using UNICODE, I can easily read in the integer value, but reading in a "char" as "wchar_t" has me a tad confused.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
char pBuffer[14];

//Attempt to read each directory structure
this-&amp;gt;fsFile.seekg(iSeek, ios::end);
for(short sLoop = 0; sLoop &amp;lt; this-&amp;gt;Header.sDirCount; sLoop++)
{
  this-&amp;gt;fsFile.get((wchar_t*)pBuffer, 14);
  this-&amp;gt;fsFile.get((wchar_t*)&amp;amp;(this-&amp;gt;pStringDir[sLoop].iSize), 4);

  //Convert the old ANSI string to UNICODE
  mbstowcs(this-&amp;gt;pStringDir[sLoop].pName, pBuffer, 14);
}
&lt;/pre&gt;&lt;br /&gt;
Does the first "fstream.get()" line read in 14 bytes, or 14 wchar_t, which is two or four times larger than an old char?  As you can see, I simply read it in as it was meant to be read, then convert it to UNICODE for the object to use.  Thanks for the help!&lt;br /&gt;
&lt;br /&gt;
*EDIT*&lt;br /&gt;
&lt;br /&gt;
Is it possible to detect an error when using "fstream.get" like it is using "fread" in C?  Forgot to ask that as well.  I'm not sure how to detect errors using fstream.&lt;br /&gt;
&lt;br /&gt;
-&lt;em&gt;&lt;strong&gt;&lt;span style="color: Red;"&gt;S&lt;/span&gt;&lt;span style="color: Purple;"&gt;e&lt;/span&gt;&lt;span style="color: Blue;"&gt;p&lt;/span&gt;&lt;span style="color: Green;"&gt;h&lt;/span&gt;&lt;span style="color: Red;"&gt;i&lt;/span&gt;&lt;span style="color: Purple;"&gt;r&lt;/span&gt;&lt;span style="color: Blue;"&gt;o&lt;/span&gt;&lt;span style="color: Green;"&gt;t&lt;/span&gt;&lt;span style="color: Red;"&gt;h&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/392376/392376/using-fstreamget-in-unicode/</guid>
      <pubDate>Mon, 15 Jun 2009 21:10:32 -0700</pubDate>
      <category>C and C++</category>
    </item>
  </channel>
</rss>