line 60: The memory allocated here is destroyed by lines 75 and 80 -- memory leak.
I don't get what parser() is supposed to do.
This is a sightly modified version of readXml function compiled with VC++ 2010 Express on Windows 7. It does not contain the problem you reported. All I did was removed malloc(), there is no point allocating memory for only 4 bytes of data. Also simplified the if-else clause in that function.
#include <stdio.h>
#include <stdlib.h>
//#include <unistd.h>
#pragma warning(disable: 4996)
#define BUFSIZE 4
void error_handler(unsigned short int err) {
char * error_desc;
switch (err) {
case 1: error_desc = "Input file could not be opened.\n";
;;
case 2: error_desc = "Input file did not exist.\n";
;;
case 3: error_desc = "Output file could not be opened\n";
;;
case 4: error_desc = "Output file could not be closed.\n";
;;
default: error_desc = "Unspecified error, aborting.\n";
;;
}
printf("Exiting with error %s\n", error_desc);
exit(err);
}
FILE * openFile (char * filen_in, char * mode, unsigned short int err) {
/* Open SAFT file. */
FILE * fp;
if ((fp = fopen (filen_in, mode)) == NULL) {
error_handler(err);
}
return fp;
}
void closeFile (FILE * fp, unsigned short int err) {
/* Close output file. */
if (fclose(fp) != 0) {
error_handler(err);
}
}
char * parser(char ** p, unsigned int dif)
{
/* Store first 2 chars of each string */
/* printf("-------------- %d %d \n", p, *p);*/
if (dif > 0) {
++*p;
}
return …