This program has all valid syntax, and no compilier errors or warnings. I am mostly posting this in order to get help on a function that doesn't seem to be doing its' job until much later. I'm also posting this for how to clear the screen more efficiently in C. My current program just checks the system platform then uses an inefficient system command for clearing the screen.

Unexpected Output : The loop I made for getting user input and storing it in the heap works, but the if statement that tests if the user enters more than they should does not execute until after the user presses enter. Basically, if I typed 100 characters, the error message won't pop up and take care of it until after a enter key press. Any help with making it pop up exactly when you exceed the limit would be appreciated.


My inefficient screen clearing code :


Code:
void ClearScreen(void) {


    #if SYSTEM==Windows
    system("cls");
    #elif SYSTEM==linux
    system("clear");
    #endif


    return;
}
My getting user input code :


Code:
    do {


        if ( CharCtr >= MemCtr ) {
        printf("\n \a Oops! Not enough allocated memory space");
        printf(" Printing received data... \n \n");


        countdown(3);


        StartOfiPtr += CharCtr;
        *StartOfiPtr = '\0';
        StartOfiPtr -= CharCtr;


        break;


        }


        scanf("%c", iPtr);


        ++iPtr;
        ++CharCtr;




    } while ( *(iPtr - 1) != '\n' );
Full program :

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>


#ifdef _WIN32
#define SYSTEM Windows
#ifndef SYSTEM
#ifdef linux
#define SYSTEM linux
#endif
#endif
#endif


void countdown(int seconds);
void countdowntoexit(int seconds);
void wait(int seconds);
void ClearScreen(void);


int main() {


    char * iPtr;
    char * StartOfiPtr;
    int CharCtr = 0;
    int MemCtr = 0;


    iPtr = (char *)malloc(MemCtr = 10 * sizeof(char));
    StartOfiPtr=iPtr;


    if ( !iPtr ) {
        printf("Memory allocation has failed!");
        exit(1);
    } else {
        printf("Memory allocation has succeeded with %d bytes allocated so far! \n \n", MemCtr);
    }


    countdown(3);


    do {


        if ( CharCtr >= MemCtr ) {
        printf("\n \a Oops! Not enough allocated memory space");
        printf(" Printing received data... \n \n");


        countdown(3);


        StartOfiPtr += CharCtr;
        *StartOfiPtr = '\0';
        StartOfiPtr -= CharCtr;


        break;


        }


        scanf("%c", iPtr);


        ++iPtr;
        ++CharCtr;




    } while ( *(iPtr - 1) != '\n' );


    *iPtr='\0';


    printf("\n You entered : %s \n \n ", StartOfiPtr);


    free(iPtr);


    countdowntoexit(5);


    return 0;
}


void countdown( int seconds ) {


    int a = 0;


    printf("\n \t \t Continuing in... ");


    for (a=0; a < seconds; a++ ) {
        printf(" %d", a+1);
        wait(1);
    }


    ClearScreen();


    return;
}


void ClearScreen(void) {


    #if SYSTEM==Windows
    system("cls");
    #elif SYSTEM==linux
    system("clear");
    #endif


    return;
}


void wait( int seconds ) {


    clock_t end_wait = { clock() + ( seconds * CLOCKS_PER_SEC ) };


    while ( clock() < end_wait ) {}


    return;


}


void countdowntoexit ( int seconds ) {


    int a = 0;


    printf("\n \t \t Exiting in... ");


    for (a=0; a < seconds; a++ ) {
        printf(" %d", a+1);
        wait(1);
    }


    return;
}


Any other suggestions you can think of would be nice if you have good ideas for improving this code.