PAGE2GO2 HOME | INTERNET NEWS

LeighExchange - Free Advertising Network Stock Research at Internet Speed

Re: unexpected character displayed infront of the variable

 List
Subject: Re: unexpected character displayed infront of the variable
Poster: user923005
Date: 23 Mar 2007 12:46:11 -0700
Related Postings: 1 2
On Mar 23, 12:43 pm, "user923005" wrote:
> On Mar 23, 12:35 pm, ehabaziz2...@gmail.com wrote:
> [snip]
>
> > do
> > {
> > i++;
> > (*cust).cust_name[i]=getchar();} while ((*cust).cust_name[i]!='\n');
>
> do {
> (*cust).cust_name[i++] = getchar();
> } while ((*cust).cust_name[i] != '\n');
>
> Or better yet (by far):
>
> fgets(cust->cust_name, sizeof cust->cust_name, stdin);
>
> [snip]

Probably better yet is Jack Klein's getsafe() function, which will remove the trailing newline character:

#include #include char *getsafe(char *buffer, int count) { char *result = buffer, *np; if ((buffer == NULL) || (count < 1)) result = NULL; else if (count == 1) *result = '\0'; else if ((result = fgets(buffer, count, stdin)) != NULL) if (np = strchr(buffer, '\n')) *np = '\0'; return result; }

 

Page2Go2.com is not responsible for content of this message.