My Boolean variables keeps changing to false even though I set them as true
What I have tried:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include "types.h"
#include "rental.h"
#include "sort.h"
bool isNumber(char strParam[])
{
for( int i = 0; strParam[i] != '\0'; i++ ) {
if( isdigit(strParam[i]) == 0 ) {
return false;
}
}
return true;
}
bool readProperties( char *strFilename, RentalProperty **ppProperties )
{
char strLine[512];
char strArgument[512];
char strRemainder[512];
char comma;
bool isStreetExist;
bool isNumExist;
bool isRentExist;
bool isRoomExist;
FILE *fileIn = fopen( strFilename, "r" );
if( fileIn == NULL ){
perror( strFilename );
return false;
}
int rc = 0;
int propertyCounter = countProperties( *ppProperties );
while ( !feof( fileIn ) )
{
isStreetExist = false;
isNumExist = false;
isRentExist = false;
isRoomExist = false;
fgets( strLine, 512, fileIn );
*ppProperties = realloc( *ppProperties, ( propertyCounter + 1 ) * sizeof( RentalProperty ) );
do {
rc = sscanf( strLine, "%[^,]%[,] %[^\n]", strArgument, &comma, strRemainder );
strcpy( strLine, strRemainder );
if( strncmp( "streetName=", strArgument, 11 ) == 0 ) {
isStreetExist = true;
( *ppProperties )[ propertyCounter ].streetName = ( char* )malloc(sizeof ( char ) );
strcpy( ( *ppProperties )[ propertyCounter].streetName, strArgument + 11 );
} else if ( strncmp( "streetNumber=", strArgument, 13 ) == 0 ) {
if( isNumber( strArgument + 13 ) == false){
fprintf( stderr, "\nError: %s - Invalid Argument", strArgument);
return false;
}
( *ppProperties )[ propertyCounter ].streetNumber = atoi( strArgument + 13 );
isNumExist = true;
} else if ( strncmp( "rent=", strArgument, 5 ) == 0 ) {
if( isNumber( strArgument + 5 ) == false){
fprintf( stderr, "\nError: %s - Invalid Argument", strArgument);
return false;
}
( *ppProperties )[ propertyCounter ].rent = atoi( strArgument + 5 );
isRentExist = true;
} else if ( strncmp( "rooms=", strArgument, 6 ) == 0 ) {
if( isNumber( strArgument + 6 ) == false){
fprintf( stderr, "\nError: %s - Invalid Argument", strArgument);
return false;
}
( *ppProperties )[ propertyCounter ].rooms = atoi( strArgument + 6 );
isRoomExist = true;
} else {
fprintf( stderr, "\nWarning: %s - Unknown argument", strArgument);
}
} while( rc > 1 );
if( isStreetExist || isNumExist || isRentExist || isRoomExist ){
}
propertyCounter++;
}
*ppProperties = realloc( *ppProperties, ( propertyCounter ) * sizeof( RentalProperty ) );
(*ppProperties)[propertyCounter - 1].rent = -1;
*ppProperties = &(*ppProperties)[0];
fclose( fileIn );
return true;
}