P
Papadopoulos Giannis
Up to today I am using the code below for File i/o:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *in, *out;
if(argc==1)
{
in = stdin;
out = stdout;
}
else
{
if(argc==2)
{
in = stdin;
if( (out = fopen(argv[1], "w"))==NULL )
{
perror("Output file creation");
exit(EXIT_FAILURE);
}
}
else
{
if( (in = fopen(argv[1], "r"))==NULL )
{
perror("Input file opening");
exit(EXIT_FAILURE);
}
if( (out = fopen(argv[2], "w"))==NULL )
{
perror("Output file creation");
fclose(in);
exit(EXIT_FAILURE);
}
}
}
/* some code here */
return EXIT_SUCCESS;
}
Am I forgetting something? Is there any addition to make the program
more robust and efficient??
--
#include <stdio.h>
#define p(s) printf(#s" endian")
int main(void){int v=1;*(char*)&v?p(Little)(Big);return 0;}
Giannis Papadopoulos
http://dop.users.uth.gr/
University of Thessaly
Computer & Communications Engineering dept.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *in, *out;
if(argc==1)
{
in = stdin;
out = stdout;
}
else
{
if(argc==2)
{
in = stdin;
if( (out = fopen(argv[1], "w"))==NULL )
{
perror("Output file creation");
exit(EXIT_FAILURE);
}
}
else
{
if( (in = fopen(argv[1], "r"))==NULL )
{
perror("Input file opening");
exit(EXIT_FAILURE);
}
if( (out = fopen(argv[2], "w"))==NULL )
{
perror("Output file creation");
fclose(in);
exit(EXIT_FAILURE);
}
}
}
/* some code here */
return EXIT_SUCCESS;
}
Am I forgetting something? Is there any addition to make the program
more robust and efficient??
--
#include <stdio.h>
#define p(s) printf(#s" endian")
int main(void){int v=1;*(char*)&v?p(Little)(Big);return 0;}
Giannis Papadopoulos
http://dop.users.uth.gr/
University of Thessaly
Computer & Communications Engineering dept.