C need help printing into file
i need to print using these #'s for testing Test Data Set :10 here you enter the size of the array 10 10 30 30 40 50 50 50 60 60
and it will print in the txt file like this
========== =========== ============
ORIGINAL ASCENDING DESCENDING
========== =========== ============
50 20 100
70 50 70
20 50 70
100 70 70
70 70 50
50 70 50
70 100 20
but its not printing any thing can someone have a look at my code and tell me what i am doing wrong?
#include <stdio.h>
#include <stdlib.h>
#include <crtdbg.h>
#define maxSize 100
#define TRUE 1
#define FALSE 0
/* Prototype Declarations */
void welcome (void);
void getData (int *array, int *arraySize);
void sortArray (int *array, int arraySize);
void printArray (int *array, int arraySize);
void farewell (void);
int main (void)
{
/* Local Definitions */
int array[maxSize];
int arraySize;
/* Statements */
welcome ();
getData (array, &arraySize);
sortArray(array, arraySize);
printArray (array, arraySize);
printf( _CrtDumpMemoryLeaks() ? "Memory Leak\n" : "No Leak\n");
farewell ( );
return 0;
} /* main */
/* ============================== welcome ==============================
Prints a welcome message.
PRE : nothing
POST : welcome message printed
*/
void welcome (void)
{
/* Local Definitions */
/* Statements */
printf("\t\t LAB 4 - Pointer Applications\n\n");
return;
} /* welcome */
void getData (int *array, int *arraySize)
{
/* LD */
int i;
/* ST */
printf("Array Size: ");
scanf("%d", arraySize);
for (i = 0; i < *arraySize; ++i)
{
printf("\nValue: ", i, *arraySize);
scanf("%d", (array + i));
}
return;
}
void sortArray (int *array, int arraySize)
{
/* LD */
int temp;
int curr;
int walk;
/* ST */
for (curr = 1; curr < arraySize; curr++)
{
temp = curr;
walk = curr - 1;
while (walk >= 0 && temp < walk)
{
walk = temp;
walk--;
}
}
return;
}
void printArray (int *array, int arraySize)
{
/* LD */
FILE *fpArray;
int i;
fpArray = fopen("array.txt", "w");
fprintf (fpArray, "========== =========== ============\n");
fprintf (fpArray, " ORIGINAL ASCENDING DESCENDING\n");
fprintf (fpArray, "========== =========== ============\n");
for (i = 0; i <= arraySize; i++)
{
if (i %3 != 0)
{
fprintf(fparray, "%6d", *(array + i));
}
else
{
fprintf(fparray, "\n");
fprintf(fparray, "%6d", *(array + i));
}
scanf("%d", i);
}
return;
}
/* ============================== farewell ==============================
Prints a farewell message.
PRE : nothing.
POST : farewell message printed
*/
void farewell (void)
{
printf("\n\t\tEnd of the program!"
"\n\t\tHave a great day!\n");
return;
} /* farewell */
and it will print in the txt file like this
========== =========== ============
ORIGINAL ASCENDING DESCENDING
========== =========== ============
50 20 100
70 50 70
20 50 70
100 70 70
70 70 50
50 70 50
70 100 20
but its not printing any thing can someone have a look at my code and tell me what i am doing wrong?
#include <stdio.h>
#include <stdlib.h>
#include <crtdbg.h>
#define maxSize 100
#define TRUE 1
#define FALSE 0
/* Prototype Declarations */
void welcome (void);
void getData (int *array, int *arraySize);
void sortArray (int *array, int arraySize);
void printArray (int *array, int arraySize);
void farewell (void);
int main (void)
{
/* Local Definitions */
int array[maxSize];
int arraySize;
/* Statements */
welcome ();
getData (array, &arraySize);
sortArray(array, arraySize);
printArray (array, arraySize);
printf( _CrtDumpMemoryLeaks() ? "Memory Leak\n" : "No Leak\n");
farewell ( );
return 0;
} /* main */
/* ============================== welcome ==============================
Prints a welcome message.
PRE : nothing
POST : welcome message printed
*/
void welcome (void)
{
/* Local Definitions */
/* Statements */
printf("\t\t LAB 4 - Pointer Applications\n\n");
return;
} /* welcome */
void getData (int *array, int *arraySize)
{
/* LD */
int i;
/* ST */
printf("Array Size: ");
scanf("%d", arraySize);
for (i = 0; i < *arraySize; ++i)
{
printf("\nValue: ", i, *arraySize);
scanf("%d", (array + i));
}
return;
}
void sortArray (int *array, int arraySize)
{
/* LD */
int temp;
int curr;
int walk;
/* ST */
for (curr = 1; curr < arraySize; curr++)
{
temp = curr;
walk = curr - 1;
while (walk >= 0 && temp < walk)
{
walk = temp;
walk--;
}
}
return;
}
void printArray (int *array, int arraySize)
{
/* LD */
FILE *fpArray;
int i;
fpArray = fopen("array.txt", "w");
fprintf (fpArray, "========== =========== ============\n");
fprintf (fpArray, " ORIGINAL ASCENDING DESCENDING\n");
fprintf (fpArray, "========== =========== ============\n");
for (i = 0; i <= arraySize; i++)
{
if (i %3 != 0)
{
fprintf(fparray, "%6d", *(array + i));
}
else
{
fprintf(fparray, "\n");
fprintf(fparray, "%6d", *(array + i));
}
scanf("%d", i);
}
return;
}
/* ============================== farewell ==============================
Prints a farewell message.
PRE : nothing.
POST : farewell message printed
*/
void farewell (void)
{
printf("\n\t\tEnd of the program!"
"\n\t\tHave a great day!\n");
return;
} /* farewell */
0