<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Copy an .exe to a new .exe file using C/C++' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Copy an .exe to a new .exe file using C/C++' posted on the 'Embedded C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Thu, 20 Jun 2013 04:13:35 -0700</pubDate>
    <lastBuildDate>Thu, 20 Jun 2013 04:13:35 -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>Copy an .exe to a new .exe file using C/C++</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/421341/421341/copy-an-exe-to-a-new-exe-file-using-cc++/</link>
      <description>Let there be an executable file say, t1.exe. If I run t1.exe then it shall copy itself to a new executable file say t2.exe.&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
	FILE *fp,*tp;&lt;br /&gt;
   	unsigned long int t=0;&lt;br /&gt;
 	tp=fopen("t2.exe","wb");&lt;br /&gt;
   	//rewind(tp);&lt;br /&gt;
 	if((fp=fopen("t1.exe","rb"))!=NULL)&lt;br /&gt;
 	{&lt;br /&gt;
     		 fseek(fp,0L,2);&lt;br /&gt;
      		 unsigned long int pos=ftell(fp);&lt;br /&gt;
      		 rewind(fp);&lt;br /&gt;
     		 do{&lt;br /&gt;
      			fputc(fgetc(fp),tp);&lt;br /&gt;
         		t++;&lt;br /&gt;
   		 }while(t!=pos+1);&lt;br /&gt;
 	}&lt;br /&gt;
&lt;br /&gt;
 	fcloseall();&lt;br /&gt;
 	//system("t2.exe");&lt;br /&gt;
 	printf("End of t1");&lt;br /&gt;
	getch();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
t2.exe is created but when I run this it says "t2 has stopped working." I'm using Windows 7(Home Basic) 64bit. The program is compiled with Borland C++ V. 5.02.&lt;br /&gt;
Amazingly, both these files have same size (in bytes).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Please reply fast!!! It's URGENT....!!!!&lt;/strong&gt;&lt;br /&gt;
Thnx!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/421341/421341/copy-an-exe-to-a-new-exe-file-using-cc++/</guid>
      <pubDate>Sat, 29 Jan 2011 07:59:30 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
  </channel>
</rss>