M
myjunkcontainer
To whom ever might be able to help me:
When I run the below code it returns the value I expect i.e. "arrays
are equal" if true and "arrays are not equal" if false as long as I
run it in Visual Studio. However, if i create a batch file, compile
with cl.exe and run, then I only get arrays are not equal - whether
they are or not. I do not understand why there is a difference. Visual
studio uses cl.exe. I have tried this using the function as an int or
as a bool and including stdbool.h. ----Please help.
/* array equality test.
Written by: clint
Date: 10-7-7
*/
#include <stdio.h>
//#include "stdbool.h"
// this file must be included in order for program to work.
//#include <stdbool.h>
// or this file can be added to the include directory
// Function Declarations
int comparearrays (int arrayA[], int arrayB[]);
int main (void)
{
// Local Declarations
//int comparerA;
//int comparerB;
int falsifier;
int arrayA[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int arrayB[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// Statements
printf("Compare ArrayA with ArrayB\n");
//testing code before building function --CS
//for (comparerA = 0, comparerB = 0; comparerA < 11; comparerA++,
comparerB++)
//{
// if (arrayA[comparerA] == arrayB[comparerB])
// {
// falsifier = 1;
// }
// else
// {
// falsifier = 0;
// break;
// }
//}
//comparearrays(arrayA, arrayB);
falsifier = comparearrays(arrayA, arrayB);
if (falsifier == 0)
{
printf("arrays are not equal\n");
}
else if (falsifier == 1)
{
printf("arrays are equal\n");
}
return 0;
} // main
/* ==================== comparearrays ====================
this function copares two arrays and returns a boolean value
where the arrays are equal or not */
int comparearrays (int arrayA[], int arrayB[])
{
int falsifier;
int comparerA;
int comparerB;
for (comparerA = 0, comparerB = 0; comparerA < 11; comparerA++,
comparerB++)
{
if (arrayA[comparerA] == arrayB[comparerB])
{
falsifier = 1;
}
else
{
falsifier = 0;
break;
}
}
return falsifier == 1;
}
/* Results:
returns boolean value and states if arrays are equal or not equal
*/
When I run the below code it returns the value I expect i.e. "arrays
are equal" if true and "arrays are not equal" if false as long as I
run it in Visual Studio. However, if i create a batch file, compile
with cl.exe and run, then I only get arrays are not equal - whether
they are or not. I do not understand why there is a difference. Visual
studio uses cl.exe. I have tried this using the function as an int or
as a bool and including stdbool.h. ----Please help.
/* array equality test.
Written by: clint
Date: 10-7-7
*/
#include <stdio.h>
//#include "stdbool.h"
// this file must be included in order for program to work.
//#include <stdbool.h>
// or this file can be added to the include directory
// Function Declarations
int comparearrays (int arrayA[], int arrayB[]);
int main (void)
{
// Local Declarations
//int comparerA;
//int comparerB;
int falsifier;
int arrayA[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int arrayB[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// Statements
printf("Compare ArrayA with ArrayB\n");
//testing code before building function --CS
//for (comparerA = 0, comparerB = 0; comparerA < 11; comparerA++,
comparerB++)
//{
// if (arrayA[comparerA] == arrayB[comparerB])
// {
// falsifier = 1;
// }
// else
// {
// falsifier = 0;
// break;
// }
//}
//comparearrays(arrayA, arrayB);
falsifier = comparearrays(arrayA, arrayB);
if (falsifier == 0)
{
printf("arrays are not equal\n");
}
else if (falsifier == 1)
{
printf("arrays are equal\n");
}
return 0;
} // main
/* ==================== comparearrays ====================
this function copares two arrays and returns a boolean value
where the arrays are equal or not */
int comparearrays (int arrayA[], int arrayB[])
{
int falsifier;
int comparerA;
int comparerB;
for (comparerA = 0, comparerB = 0; comparerA < 11; comparerA++,
comparerB++)
{
if (arrayA[comparerA] == arrayB[comparerB])
{
falsifier = 1;
}
else
{
falsifier = 0;
break;
}
}
return falsifier == 1;
}
/* Results:
returns boolean value and states if arrays are equal or not equal
*/