Alright. Im a beginning C programmer, and im having a few difficultys with a piece of code im tryin to get working.

Its a small program to view whatever you have lying around in your memory. My problem is for some reason or another it refuses to call a getchar() function the first time round and try as I might I cant figure out why. So I thought I'd post it here and let you guys pick it apart and see if you can shed some light on whats gone wrong here. (Comeon, its only a small piece of code.. Help a guy out.. Please?)

Ok, most of it is pretty straight forward. The variable memstart is a integer for now because it was being antisocial when it was a long integer. But thats not my problem for now. My problem is after the first 2 for loops are finished it should call the function getchar() to pause the screen until the user hits the enter button. It dosen't. It works fine at the end of the 2nd and so on loops, but just not for the first loop. The first page of information goes whizzing off the top of the page before anyone can get a chance to read it. Ive tried stepping through the code, and it appears to be calling it, but it just dosent call! I suspect my while(1) infinite loop is somehow causing the problem, but I have no idea how. Thats an ugly piece of code anyway. Anyway, ive stuck comments all through it to try and help explain whats going on. It looks rather ugly just pasted into the page like that, so I also attached the source code to this thread so you can download it till your hearts content. (I changed the extention to .txt, cos this server dosen't like you attaching .c files)

#include <stdio.h>
#include <ctype.h>
#define COLUMN_NUMBER 55 /* Constant for number of columns printed to screen */
#define ROW_NUMBER 20 /* Constant for number of rows printed before a page break */
unsigned int rowcounter, columncounter, memincrement = 0, *ptr;
unsigned int memstart; /* Value of first memory byte to start at */
unsigned int charconvert; /* Takes the character to be printed to the screen from the pointer */
void main(void)
printf("\nEnter starting memory value: ");
scanf("%d", &memstart); /* Yeah, memory value to start at */
while (1) /* An infinite loop. I suspect this could be causing my problems... */
for (rowcounter = 0; rowcounter < ROW_NUMBER; rowcounter++)
printf("%d ", ptr);
for (columncounter = 0; columncounter < COLUMN_NUMBER; columncounter++)
ptr = memstart + memincrement; /* Point the pointer at the memory value we wish to examine */
charconvert = (char) *ptr; /* Pass the value to the variable charconvert */
if (isprint(charconvert)) /* Check that its a printable character, dont want to go around printing tabs or page breaks or stuff */
printf ("%c", charconvert);
printf (" ");
memincrement++; /* Increment the variable that controls where the pointer points to */
getchar(); /* My problem. It calls fine after the 1st cycle, but refuses to call the first time. Why??? I suspect my infinite loop has some part in this problem */

Can anyone shed some light on what is going on here? Any help would be greatly appreciated. Its a minor problem, but one that is annoying me no end. Thankyou.