Basic C Language question
Basic C Language question
- Subject: Basic C Language question
- From: Isaac Rivera <email@hidden>
- Date: Sun, 8 Aug 2004 16:12:19 -0400
Xcoders:
Newbie trying to learn C here.
Why wont this code behave as expected?
<SNIPET>
#include <stdio.h>
#include <stdlib.h>
// Length of the input buffer:
#define BUFFER_LEN 10
// Maximum number of strings:
#define NUM_P 10
int main () {
// Input buffer:
char buffer[BUFFER_LEN];
// Array of string pointers:
char *ps[NUM_P] = { NULL };
// Pointer to the buffer:
char *pBuffer = buffer;
// Iterators:
int i = 0, j = 0;
for(i = 0; i < NUM_P; i++)
{
// Set pointer to the beginning of buffer;
pBuffer = buffer;
// Prompt for input:
printf("\nEnter %s message, or press \"ENTER\" to end:\n", i > 0 ?
"another" : "a");
// Read a string of up to BUFFER_LEN characters:
while(((pBuffer - buffer) < BUFFER_LEN - 1) && ((*pBuffer++ =
getchar()) != '\n'));
</SNIPET>
Shouldn't the last line of code kill the while loop when one types 9
characters in a row?
But it doesn't it keeps on taking imput as long as I don't press ENTER.
Why is this?
Isaac Rivera
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.