Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Two questions about a program in C

Reply
Thread Tools

Two questions about a program in C

 
 
Eoghan
Guest
Posts: n/a
 
      02-08-2008
Well, as some of you said, I left my computer for 5 minutes, I
executed the program again and fflush didn't work anymore!

But I think I solved the problem. Because I used this version of
scanf: scanf("%[^\n]", Dato), the \n character was never read. So
using the function proposed by Ben Bacarisse, everything seems to be
allright.
Do you think that this way to use scanf could have been the problem?

Anyway, abaout the use of enum logic:
I buill the source with VC6 and XCode but I didn't have problems. I
had problems with and older version of XCode. However, you have said
that the enumerations are included in ansi '89 standard of C++, but
also in the ansi '89 of C?
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      02-08-2008
In article <(E-Mail Removed)>,
Eoghan <(E-Mail Removed)> wrote:
>However, you have said
>that the enumerations are included in ansi '89 standard of C++, but
>also in the ansi '89 of C?


No, the first C++ standard was 1998, not 1989.

The 1989 ANSI C standard describes enumerations in sections
3.1.2.5, 3.5.2.2, and 3.5.2.3.
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-08-2008
Eoghan <(E-Mail Removed)> writes:

> But I think I solved the problem. Because I used this version of
> scanf: scanf("%[^\n]", Dato), the \n character was never read. So
> using the function proposed by Ben Bacarisse, everything seems to be
> allright.
> Do you think that this way to use scanf could have been the problem?


Yes. I think about three (maybe more!) people have posted remarks to
say that not reading past the newline character is the root of the
problem.

> Anyway, abaout the use of enum logic:
> I buill the source with VC6 and XCode but I didn't have problems. I
> had problems with and older version of XCode. However, you have said
> that the enumerations are included in ansi '89 standard of C++, but
> also in the ansi '89 of C?


You have to decide if you want C or C++ code. All versions of both
language standards have enumerations, but in C++ you can omit the
"enum" keyword because the enumeration tag acts as a type name. In C
it does not (and that applies to all versions of the language
standard).

--
Ben.
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      02-09-2008
Eoghan wrote:
>
> Hi there! I have two simple questions about a program i'm doing:
> 1) if I write:
> enum logic {VERO=1, FALSO=0};


> Is this correct according to the ANSI '89 standard?


That line is correct, but I think that
any of these ways to write it, would be better:

enum logic {FALSO = 0, VERO};

enum logic {FALSO, VERO};

enum logic {FALSO = 0, VERO = 1};

--
pete
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      02-09-2008
On Fri, 8 Feb 2008 13:56:50 -0800 (PST), Eoghan <(E-Mail Removed)>
wrote in comp.lang.c:

> On the web fpurge is said to be included in stdio.h


Said by whom? What compiler, for what platform, are they talking
about?

If there is not an option to disable its inclusion in <stdio.h>, then
the implementation is not conforming.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      02-09-2008
pete wrote:
> Eoghan wrote:
>> Hi there! I have two simple questions about a program i'm doing:
>> 1) if I write:
>> enum logic {VERO=1, FALSO=0};

>
>> Is this correct according to the ANSI '89 standard?

>
> That line is correct, but I think that
> any of these ways to write it, would be better:
>
> enum logic {FALSO = 0, VERO};
>
> enum logic {FALSO, VERO};
>
> enum logic {FALSO = 0, VERO = 1};


... but don't make this mistake, which a colleague
of mine once uncovered in somebody's actual code:

typedef enum { TRUE, FALSE } Boolean;

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
Eoghan
Guest
Posts: n/a
 
      02-09-2008
Ok, Thanks to everybody!
 
Reply With Quote
 
Ralf Damaschke
Guest
Posts: n/a
 
      02-11-2008
Eoghan wrote:

> while(str[k]!=' ' && str[k]!='\0') Sigle[Nstr][k]=str[k++];


Here is another problem: in the assignment statement k is
modified and its prior value is also used (for other purpose
than to determine the value [of k] to be stored): that causes
undefined behavior and whatever happens - it may well be not
what you wanted.

Ralf
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
How to compare two SOAP Envelope or two Document or two XML files GenxLogic Java 3 12-06-2006 08:41 PM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM
Two ISP -Two Routers - 1 PIX James Parks Cisco 5 12-11-2003 08:55 PM
Cisco 2611 with Two T1 from two ISPs Adam Embrey Cisco 3 07-24-2003 10:22 PM



Advertisments