LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2007, 03:00 AM   #1
Jacko123
LQ Newbie
 
Registered: Mar 2007
Posts: 13

Rep: Reputation: 0
windows to linux


Hi All,
My first post. I have written a code snippet which works on windows. I want it to make run on linux too.

Please help.
Code:
#include <stdio.h>
#include <stdlib.h>

int main ()
{
  FILE *inFile, *outFile;
  char * buffer;
  size_t inResult;
  size_t outResult;

  char tempFilePath[L_tmpnam_s];
  errno_t err;

  tmpfile_s(&outFile);
	
  if( outFile )
  {	  
	  err = tmpnam_s( tempFilePath, L_tmpnam_s );
      if (err)
      {
         printf("Error occurred creating unique filename.\n");
         exit(1);
      }
      else
      {
         printf( "%s is safe to use as a temporary file.\n", tempFilePath );
      }
	

	  fopen_s(&inFile, "test.txt", "rb");
	  if( !inFile )
		{
        printf("Error Opening inFile\n");
		return 0;
		}

	  // obtain file size:
	  fseek (inFile , 0 , SEEK_END);
	  long lSize = ftell (inFile);
	  rewind (inFile);
	  buffer = (char*) malloc (sizeof(char)*lSize);
	  if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

	  inResult = fread (buffer, 1, lSize, inFile);
	  if (inResult != lSize)
	  {
		  fputs ("Reading error",stderr); 
		  exit (3);
	  }	
		
	  outResult = fwrite( buffer, 1, inResult, outFile );
	  if (outResult != inResult)
	  {
		  fputs ("Reading error",stderr); 
		  exit (3);
	  }	

  }
  free(buffer);
  fclose (inFile);
  fclose (outFile);	
  return 0;
}
 
Old 03-01-2007, 03:14 AM   #2
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
Have you tried compiling it?
Howto compile:
http://web.cecs.pdx.edu/~bjorn/CS200/linux_tutorial/
 
Old 03-01-2007, 07:22 AM   #3
vedanu
LQ Newbie
 
Registered: Feb 2007
Location: Bangalore
Distribution: Fedora
Posts: 18

Rep: Reputation: 0
Quote:
Originally Posted by muha
Have you tried compiling it?
Howto compile:
http://web.cecs.pdx.edu/~bjorn/CS200/linux_tutorial/
Without compiling while will the OPS post the code. Are u getting any errors.

I used
cc main.c

Gives errors
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing a Windows Domain Controller with a Linux:OpenLDAP importing from Windows AD mstevensfullarmor Linux - Enterprise 14 02-15-2012 06:05 PM
Solution Dual Boot Windows & Linux [ALL DONE IN WINDOWS] No Linux terminology DSargeant Linux - Newbie 35 02-07-2006 03:29 PM
Solution Dual Boot Windows & Linux [ALL DONE IN WINDOWS] No Linux terminology DSargeant Linux - Newbie 4 11-10-2005 11:37 AM
Red Hat Linux 9 + Windows Server 2003 + Windows XP + Fedora in same domain wolfy339 Linux - Networking 5 03-02-2005 06:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration