Can C do it ?

B

bpascal123

It is a waste of time to learn the wrong what and then the right way.

To the OP: consider getting a copy of K&R2.

Hi,

Some have been requestiong where i was getting my tut from. I was
reluctant to answer because it's in french and for many it wouldn't
mean much.

Here it is : http://www.ltam.lu/Tutoriel_Ansi_C/

look at application 8.8

And the solution to the application is there : http://www.ltam.lu/Tutoriel_Ansi_C/homesol.htm

Often for this tutorial i find the solution from the author not
applicable outside this tutorial. Even if for now, i don't find
exciting calling that DOS or Unix terminal to see the outputs of what
i'm learning, i hope soon to apply this on more human stuff maybe on
cell phones or whatever...
That's why i'd like to add some more stuff that would make it look
more real if i would use it outside this tutorial.

In the 8.8, the solution works well with little changes from what is
published (maybe a long time ago) :

#include <stdio.h>
#include <string.h>
main()
{
/* Déclarations */
char VERB[20]; /* chaîne contenant le verbe */
char AFFI[30]; /* chaîne pour l'affichage */
int L; /* longueur de la chaîne */

/* Saisie des données */
printf("Verbe : ");
fgets(VERB, 20, stdin) ;

/* Contrôler s'il s'agit d'un verbe en 'er' */
L=strlen(VERB);
if ((VERB[L-3]!='e') || (VERB[L-2]!='r'))
puts("\aCe n'est pas un verbe du premier groupe.!");
else
{
/* Couper la terminaison 'er'. */
VERB[L-3]='\0';
/* Conjuguer ... */
AFFI[0]='\0';
strcat(AFFI, "je ");
strcat(AFFI, VERB);
strcat(AFFI, "e");
puts(AFFI);

}
return 0;
}

It just prints one pronoun otherwise you'd have to write the last
block down from "/*conjuguer ...*/" as many time as there are
pronouns.

I don't find this very efficient when a loop can tweak it and print
all pronouns.

I understand the author did just want to focus on string.h functions.

Because i'm spending 40 % of my time learning by heart, blocks of
structures and functions,
40 % doing applications from the tutorial above,
10 % reading and browsing the web for information
and the last 10 % locating bugs.

Learning by heart is special but i'm lazy and i kinda find it easier
than starting an application from scratch... If i find myself a way
to achieve an application from this tutorial, let say with 2 more
loops and 1 or 2 more if (my code is heavier than the author's) then,
i find it less rewarding as when i can apply something i have learned
by heart and it works.

Pascal
 
B

bpascal123

It is a waste of time to learn the wrong what and then the right way.

To the OP: consider getting a copy of K&R2.

Hi,

Some have been requestiong where i was getting my tut from. I was
reluctant to answer because it's in french and for many it wouldn't
mean much.

Here it is : http://www.ltam.lu/Tutoriel_Ansi_C/

look at application 8.8

And the solution to the application is there : http://www.ltam.lu/Tutoriel_Ansi_C/homesol.htm

Often for this tutorial i find the solution from the author not
applicable outside this tutorial. Even if for now, i don't find
exciting calling that DOS or Unix terminal to see the outputs of what
i'm learning, i hope soon to apply this on more human stuff maybe on
cell phones or whatever...
That's why i'd like to add some more stuff that would make it look
more real if i would use it outside this tutorial.

In the 8.8, the solution works well with little changes from what is
published (maybe a long time ago) :

#include <stdio.h>
#include <string.h>
main()
{
/* Déclarations */
char VERB[20]; /* chaîne contenant le verbe */
char AFFI[30]; /* chaîne pour l'affichage */
int L; /* longueur de la chaîne */

/* Saisie des données */
printf("Verbe : ");
fgets(VERB, 20, stdin) ;

/* Contrôler s'il s'agit d'un verbe en 'er' */
L=strlen(VERB);
if ((VERB[L-3]!='e') || (VERB[L-2]!='r'))
puts("\aCe n'est pas un verbe du premier groupe.!");
else
{
/* Couper la terminaison 'er'. */
VERB[L-3]='\0';
/* Conjuguer ... */
AFFI[0]='\0';
strcat(AFFI, "je ");
strcat(AFFI, VERB);
strcat(AFFI, "e");
puts(AFFI);

}
return 0;
}

It just prints one pronoun otherwise you'd have to write the last
block down from "/*conjuguer ...*/" as many time as there are
pronouns.

I don't find this very efficient when a loop can tweak it and print
all pronouns.

I understand the author did just want to focus on string.h functions.

Because i'm spending 40 % of my time learning by heart, blocks of
structures and functions,
40 % doing applications from the tutorial above,
10 % reading and browsing the web for information
and the last 10 % locating bugs.

Learning by heart is special but i'm lazy and i kinda find it easier
than starting an application from scratch... If i find myself a way
to achieve an application from this tutorial, let say with 2 more
loops and 1 or 2 more if (my code is heavier than the author's) then,
i find it less rewarding as when i can apply something i have learned
by heart and it works.

Pascal
 
B

Ben Bacarisse

"wrong way" of course.

Its best to snips sigs -- even short ones. Better, also, to leave the
attribution line (the "so and so writes:" bit at the top) which you've
cut.
Some have been requestiong where i was getting my tut from. I was
reluctant to answer because it's in french and for many it wouldn't
mean much.

Here it is : http://www.ltam.lu/Tutoriel_Ansi_C/

Apart from the detail of using gets, the worst of it the order in which
things are introduced. Casts (rarely needed/used) come in chapter 3
but function have to wait until chapter 10 (last but one). Pointers
(a basic overview thereof) should be covered at the same time as
arrays and after functions so you can start to write functions to do
interesting things with arrays and, later, strings.
look at application 8.8

And the solution to the application is there : http://www.ltam.lu/Tutoriel_Ansi_C/homesol.htm
In the 8.8, the solution works well with little changes from what is
published (maybe a long time ago) :

#include <stdio.h>
#include <string.h>
main()
{
/* Déclarations */
char VERB[20]; /* chaîne contenant le verbe */
char AFFI[30]; /* chaîne pour l'affichage */
int L; /* longueur de la chaîne */

/* Saisie des données */
printf("Verbe : ");
fgets(VERB, 20, stdin) ;

/* Contrôler s'il s'agit d'un verbe en 'er' */
L=strlen(VERB);
if ((VERB[L-3]!='e') || (VERB[L-2]!='r'))
puts("\aCe n'est pas un verbe du premier groupe.!");
else
{
/* Couper la terminaison 'er'. */
VERB[L-3]='\0';
/* Conjuguer ... */
AFFI[0]='\0';
strcat(AFFI, "je ");
strcat(AFFI, VERB);
strcat(AFFI, "e");
puts(AFFI);

}
return 0;
}

It just prints one pronoun otherwise you'd have to write the last
block down from "/*conjuguer ...*/" as many time as there are
pronouns.

I don't find this very efficient when a loop can tweak it and print
all pronouns.

It's absurd. The code presents includes ". . ." showing where you
have to repeat all the code! This is what functions a for.

<snip>
 
K

Keith Thompson

[snip]

Pascal, your articles are showing up 2 or 3 time each. Suggestion:
Don't assume a post hasn't gone through until you've checked the
newsgroup a while later.
 
K

Keith Thompson

Nick Keighley said:
A contiguous sequence of chars is not a char. Hence this makes
no sense

char nifnif[2] = "je";

that's an array of two characters whilst "je" is a string or
pointer-to-char. A pointer-to-char won't go in a char.
[...]

Actually, it does. It sets nifnif[0] to 'j' and nifnif[1] to 'e'.
It's potentially dangerous, though; since the size of the array
exactly matches the length of the string literal, no trailing '\0' is
stored (this is a special-case rule).

To avoid that problem:
char nifnif[] = "je";
This makes the compiler determine the length of the string;
sizeof nifnif will be 3.

An initializer for a char array is one of the three contexts in which
an array expression *isn't* implicitly converted to a pointer to the
array's first element (the other two being the operand of a unary "&"
or "sizeof" operator).
 
C

Curtis Dyer

Hi,

Some have been requestiong where i was getting my tut from. I
was reluctant to answer because it's in french and for many it
wouldn't mean much.

You might be interested to know that K&R2 has been translated into
many languages, including French.

From the K&R2 site <http://cm.bell-labs.com/cm/cs/cbook/>:

# French: Le Langage C, Masson, ISBN 2-225-82070-8
# French: Le Langage C: Norme ANSI, Dunod, ISBN 2-100-05116-4 (2nd
ed.)

<snip>
 
B

bpascal123

Hi,

I think a comfortable level in algorithmic is required to learn from
this book as i've seen some its applications on the web. It really
looked above my present understanding and expectation of programming.

Below is what took me a few hours :( from the first post in this
discussion.

There are 2 codes ; the first one with pointers, the second one with
structures arrays.

I'm not sure but i think the second post is closer to what i'd
implement with higher languages... There are still pointers in it but
it seems to me the layout is closer to higher programming languages.
Extracting pointers from it is out of reach for me...

I don't want to avoid pointers, i just would like to find there are
alternatives to pointers. It sounds weird since pointers are the core
of C... I also think, pointers skip some algorithms implementation. At
a very basic level like mine in programming, i find it easier to lay
down code code on a blank paper with a pen and algorithm rather than
start straight with pointers...

===

#include <stdio.h>
#include <string.h>

/* THIS PROGRAM CONJUGATES A FRENCH VERB FROM THE 1ST GROUP
(like chanter, penser...) AT PRESENT TIME USING UBIQUITOUS C
POINTERS*/

int main(void)
{

int n = 20 ;
char Verb[n] ;
char Verb2[n] ;
int i, j, cnt ;

/* Below is largely inspired from Pete's code in this
discussion */

const char *pro[] = { "je", "tu", "il", "elle", "nous", "vous",
"ils", "elles" } ;
const char *term[] = { "e", "es", "e", "e", "ons", "ez", "ent",
"ent" } ;

puts("\n\nEntrez un verbe du 1er groupe : ") ;
fgets(Verb, 20, stdin) ;
puts("------------\n");
cnt = strlen(Verb) ;

strcpy(Verb2, Verb) ;

if ( (Verb2[cnt-3] != 'e') && (Verb2[cnt-2] != 'e') )
puts("\aCe n'est pas un verbe du premier groupe.!");
else
Verb2[cnt-3] = '\0' ;

for (i = 0, j = 0; i < sizeof pro / sizeof pro[0], i < sizeof
term / sizeof term[0]; i ++)
printf("%s %s%s\n", pro, Verb2, term ) ;

printf("\n\n");

return 0;
}

===

===


#include <stdio.h>
#include <string.h>

/* THIS PROGRAM CONJUGATES A FRENCH VERB FROM THE 1ST GROUP
(like chanter, penser...) AT PRESENT TIME USING STRUCTURES*/

typedef struct Conju Conju2 ;

struct Conju
{
char *Pro ;
char *Term ;
} ;

int main(void)
{

Conju2 Conju[7] ;

int n ;

char verb[40] ;
char verb2[40] ;

int i ; int cnt ; int cnt2 ; int cnt3 ;

Conju[0].Pro = "Je " ;
Conju[1].Pro = "Tu " ;
Conju[2].Pro = "Il ";
Conju[3].Pro = "Elle ";
Conju[4].Pro = "Nous " ;
Conju[5].Pro = "Vous ";
Conju[6].Pro = "Ils " ;
Conju[7].Pro = "Elles " ;

Conju[0].Term = "e" ;
Conju[1].Term = "es" ;
Conju[2].Term = "e" ;
Conju[3].Term = "e" ;
Conju[4].Term = "ons";
Conju[5].Term = "ez" ;
Conju[6].Term = "ent" ;
Conju[7].Term = "ent " ;

printf("\n\nEntrez un verbe du 1er groupe : ") ;
fgets(verb, 50, stdin) ;

cnt = strlen(verb) ;

strcpy(verb2, verb) ;

if ( (verb2[cnt - 3] != 'e') || (verb2[cnt - 2] != 'r') )
printf("\nCe n'est pas un verbe du 1er groupe") ;
else
verb2[cnt-3] = '\0' ;

printf("\n\n%s", verb) ;
printf("\n\n%s\n\n", verb2 ) ;

for ( i = 0 ; i < 8 ; i++ )
printf("\n%s%s%s", Conju.Pro, verb2, Conju.Term) ;

printf("\n\n") ;

return 0 ;
}


I just think the 2nd code is closer to higher programming languages...

Pascal
 
B

Barry Schwarz

On Sun, 2 Aug 2009 05:12:28 -0700 (PDT), "(e-mail address removed)"

snip
#include <stdio.h>
#include <string.h>

/* THIS PROGRAM CONJUGATES A FRENCH VERB FROM THE 1ST GROUP
(like chanter, penser...) AT PRESENT TIME USING UBIQUITOUS C
POINTERS*/

int main(void)
{

int n = 20 ;
char Verb[n] ;
char Verb2[n] ;

This is valid only in C99.
int i, j, cnt ;

/* Below is largely inspired from Pete's code in this
discussion */

const char *pro[] = { "je", "tu", "il", "elle", "nous", "vous",
"ils", "elles" } ;
const char *term[] = { "e", "es", "e", "e", "ons", "ez", "ent",
"ent" } ;

puts("\n\nEntrez un verbe du 1er groupe : ") ;
fgets(Verb, 20, stdin) ;
puts("------------\n");
cnt = strlen(Verb) ;

strcpy(Verb2, Verb) ;

if ( (Verb2[cnt-3] != 'e') && (Verb2[cnt-2] != 'e') )

Surely the last expression should be 'r' and the && should be ||. As
it reads now, the verb etre will pass your test.
puts("\aCe n'est pas un verbe du premier groupe.!");

It's nice to put out the error message but then you process the data
anyway as if it were acceptable input.
else
Verb2[cnt-3] = '\0' ;

Are you sure there are no 19 letter verbs?
for (i = 0, j = 0; i < sizeof pro / sizeof pro[0], i < sizeof
term / sizeof term[0]; i ++)

First, can the two quotients ever be different?

Second, are you aware that the comma operator discards the results of
the left operand? Therefore, sizeof pro takes no part in determining
if the loop should terminate. If you really need to check both, you
probably want the logical and (&&) operator.
printf("%s %s%s\n", pro, Verb2, term ) ;

printf("\n\n");

return 0;
}

===

===


#include <stdio.h>
#include <string.h>

/* THIS PROGRAM CONJUGATES A FRENCH VERB FROM THE 1ST GROUP
(like chanter, penser...) AT PRESENT TIME USING STRUCTURES*/

typedef struct Conju Conju2 ;

struct Conju
{
char *Pro ;
char *Term ;
} ;

int main(void)
{

Conju2 Conju[7] ;

int n ;

char verb[40] ;
char verb2[40] ;

int i ; int cnt ; int cnt2 ; int cnt3 ;

Conju[0].Pro = "Je " ;
Conju[1].Pro = "Tu " ;
Conju[2].Pro = "Il ";
Conju[3].Pro = "Elle ";
Conju[4].Pro = "Nous " ;
Conju[5].Pro = "Vous ";
Conju[6].Pro = "Ils " ;
Conju[7].Pro = "Elles " ;


Unfortunately, this object does not exist.
Conju[0].Term = "e" ;
Conju[1].Term = "es" ;
Conju[2].Term = "e" ;
Conju[3].Term = "e" ;
Conju[4].Term = "ons";
Conju[5].Term = "ez" ;
Conju[6].Term = "ent" ;
Conju[7].Term = "ent " ;

Neither does this one.
printf("\n\nEntrez un verbe du 1er groupe : ") ;
fgets(verb, 50, stdin) ;

verb is only 40 char, not 50.
cnt = strlen(verb) ;

strcpy(verb2, verb) ;

if ( (verb2[cnt - 3] != 'e') || (verb2[cnt - 2] != 'r') )
printf("\nCe n'est pas un verbe du 1er groupe") ;

You did the if right but you still process the invalid data.
else
verb2[cnt-3] = '\0' ;

printf("\n\n%s", verb) ;
printf("\n\n%s\n\n", verb2 ) ;

for ( i = 0 ; i < 8 ; i++ )
printf("\n%s%s%s", Conju.Pro, verb2, Conju.Term) ;


The last iteration invokes undefined behavior.
 
R

Richard Bos

Some have been requestiong where i was getting my tut from. I was
reluctant to answer because it's in french and for many it wouldn't
mean much.

Here it is : http://www.ltam.lu/Tutoriel_Ansi_C/

Ditch it. It doesn't know whether it is a tutorial for ISO C (and what
do Frenchmen have to do with ANSI, anyway), C for MS-DOS, or Borland C;
in fact, the writer even seems to think that Borland's choices for
integer sizes are a requirement of MS-DOS, which isn't the case. It uses
gets(), and doesn't mention that this is a highly dangerous function
which should never be used; this is always a sign of an author who
shouldn't be teaching, but learning himself. It declared main as main(),
which is strictly speaking correct, but bad style. And as has already
been said, the order in which it does things is educationally unwise.

In short, it is a bad tutorial. What's worse, it is a deceptively bad
tutorial, because while not good, it is also not atrocious, so if you're
a beginner, it _looks_ like quite a good tutorial. But it will lead you
astray - in fact, it already _is_ leading you astray.

Ditch it. Get K&R instead.

Richard
 
F

Falcon Kirtaran

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jacob said:
Hi,

I'd like to know if it would be possible to store constant string in
an array. I'd first like to avoid pointers so i can see how far we go
without pointers.

Example :

-o-
char str[8] ;

char str[0] = "ab" ;
char str[1] = "cd" ;
...
char str[7] = "op" ;
-o-

No. C can't do it.

You can't store two characters in the space reserved for one...

If that would be possible RAM manufactures would go broke within minutes
:)

2° Would using a structure be more suitable?

Maybe. You haven't told use what you want to do.

3° What about a 2 dimensional array (even if it's a pain in c, with a
good algorithm behind, it should go through)...

4° And at last, if pointers were unvoidable would it be like this ?

-o-
char str[8] ;
char *pstr = str ;

pstr[0] = "ab";
pstr[1] = "cd" ;
-o-


Again the same mistake.

pstr[0] is ONE character wide. "ab" is TWO characters wide.

To nitpick somewhat, "ab" is as wide as the pointer width, and it points
to a constant array of size sizeof(char)*3. pstr[0] = "ab"; would
probably generate a warning about converting pointers to ints without
casts and another one about truncating int to char.

- --
- --Falcon Darkstar Christopher Momot
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJKdglkAAoJEOGPymTbQp7GFxIQALO3Lsos6czp6GosvZeB5kwu
BVAB6S/oyLsEXuBpqFac7c3D4JVjyhuT6h0/YyTTgNirASvoNUi4RJBb1zEAFVPt
oIaR6ALFVDM05Dw5AgKauR5XHVvlU6S0hNc32SzhneSeXbqmbtg9cjEwLqvrb/Rq
jIbh4J/aXB0OZ24RWgNIy3Jtr9oAlxMOBd4YF7ZJGVyTTTLo8q+fV1cyocGFYrPN
pbI0vpkMLR4xF32p5/MEtARdCI7xMXTAURZPifcbVU7YZJ7meW9LcAQbt2+SaKyN
ODRh+W9nJZqqhhXTAlTXoWVwIL/Ipq/K7dA+g8mW4QdyA3ZvFLqfzAKwAIW/90DA
fZ+jvuFmwPyHAkGRJeAHX8RTL2xqpNiLx1Qk8aeSwSIreCYWci8ssCevqhkQuNyo
kIJczUMj2NV4sfvcw/5WbHJh3QqwYGiz18BMsjhl/+rDdWeErNt7HhnOtRNpxh5d
PObkOOvJ7yJpbtjSTgHBJqlxWnZrPFCEeshmPwCzizi1fnPw+Eph3VwdFASF5Q9u
PWCp6MdTQLl5VqBIhjGQD94gcji2TLebn+EoCYMzXDtukIW0EhqcA709VXW9UOqZ
DszceiRhO+nm0vyK5yNkzJISub4MmPUL0IbJe72Q5ZTaZTaO7ZKE8UC0/Ye2KRtv
8AbcYIEEhmxWWHRoAB+q
=v5mX
-----END PGP SIGNATURE-----
 
K

Keith Thompson

Falcon Kirtaran said:
jacob navia wrote: [...]
Again the same mistake.

pstr[0] is ONE character wide. "ab" is TWO characters wide.

To nitpick somewhat, "ab" is as wide as the pointer width, and it points
to a constant array of size sizeof(char)*3. pstr[0] = "ab"; would
probably generate a warning about converting pointers to ints without
casts and another one about truncating int to char.

To nitpick a bit more, "ab" itself is three characters wide in
most contexts ('a', 'b', '\0'). Since it's an array expression,
it's implicitly converted to a char* pointer to the array's first
element in most, but not all, contexts.

Yet another exception is that this:

char not_a_string[2] = "ab";

is legal, and sets not_a_string to { 'a', 'b' } (no terminating '\0').
 
B

bpascal123

The last iteration invokes undefined behavior.

Hi,

Why if the code compiles well under linux and windows without
warnings, should i be looking for "perfection" ?

I'll read your review carefully so i see what i need to bring my
attention on or just what i need to "update" even if i'm just starting
to learn. Thanks in any case.

Your review might help understand why almost the same structure apply
to english verbs is not working, it prints things like :

I
sing
....
He
sings
....

For the english version, let say to make thinks simple, i skip any
other verb that end with -y or -o ...

About the tutorial where i'm learning C, i have to say again i don't
feel to complain much because it's free and simple to start with. I
chose a french tutorial because i didn't think i'll rely so much on
usenet and in the french versions, replies for similar posts as this
one can take a long time... As i said, i'm not waiting a reply before
keeping on learning something else but french usenet discussions are
not so "active".

This tutorial even if the code is "outdated" makes reference to
algorithms structures. I think algorithms is something i must
concentrate on if one day i don't want to keep learning things by
heart and learn other languages. I have to say i didn't attend ant
computer or programming courses in college or university so i don't
know really apart from looking on the web, how a computer language
degree is made with.

And if i feel like starting with any other good C book, i have to go
through this basic tutorial and like any other ones (i have seen
similar ones in english with applications also that looked
interesting...).

I was wondering, why are there so few C online courses offers ? C++,
Java Certificates are very common but C???

Is learning C like learning how to walk and C++ or Java how to drive ?

Thx,

Pascal
 
K

Keith Thompson

Why if the code compiles well under linux and windows without
warnings, should i be looking for "perfection" ?
[...]

Because a lack of warnings doesn't imply that the code is correct,
and compilers are generally unable to warn about undefined behavior.
(The language defines certain errors as undefined behavior precisely
because they're errors that the compiler can't always be expected
to diagnose.)

The worst possible result of undefined behavior is that the program
behaves just as you expect it to. That doesn't mean you were lucky;
it means the error will be more difficult to track down -- until
it goes bad at exactly the worst possible moment.

(I'm basing this just on Barry's comment -- for which, BTW, you
deleted the attribution line. I haven't studied your code.)
 
J

James Kuyper

Hi,

Why if the code compiles well under linux and windows without
warnings, should i be looking for "perfection" ?

You shouldn't be worried about perfection yet, you've got a very long
way to go before worrying about that. For now, worry about removing the
most serious defects in your code - and undefined behavior is one of the
most serious categories of defects your code can have. One of the key
reasons why it is so serious is that compilers are not required to
diagnose it, and the reason why they're not required to do so is that,
on many implementations, diagnosing any particular instance of undefined
behavior might be too difficult to justify requiring those
implementations to do so.

The fundamental problem that he's referring to is the fact that the
Conju array was declared as having only 7 elements, whereas your code,
in three different places, refers to Conj[7], which would (if it did not
have undefined behavior) refer to the non-existent 8th element of the
array. This might work without a problem if the position where the 8th
element would go doesn't happen to be currently in use by any other part
of the program, but that's just random luck, and it's bad luck, because
it makes your program appear to work correctly despite the fact that it
has a very serious problem.
 
B

Barry Schwarz

Hi,

Why if the code compiles well under linux and windows without
warnings, should i be looking for "perfection" ?

Perfection may or may not be a goal worth striving for. I leave that
to the philosophers, especially since I cannot help you get there. My
comments were aimed much lower, just mere competence. If you don't
think undefined behavior is something worth eliminating, even for a
hobbyist, then you are wasting your time here as well as ours.
 
N

Nick Keighley

I think a comfortable level in algorithmic is required to learn from
this book

I've no idea what "comfortable level in algorithmic" means.
("comfortable with algorithms"?). But I'm pretty sure K&R doesn't
require it.

as i've seen some its applications on the web.

you've seen K&R quoted on the web?

It really
looked above my present understanding and expectation of programming.

it does take careful reading. But your care is well rewarded.

<snip>
 
N

Nick Keighley

Some have been requestiong where i was getting my tut from. I was
reluctant to answer because it's in french and for many it wouldn't
mean much.

sorry couldn't resist:-

"tut: Noun. Rubbish, nonsense. E.g."Whatever he told you about me is
just a load of tut."" Dictionary of Slang

:)
 
B

bpascal123

Hi Barry,
int main(void)
{
int n = 20 ;
char Verb[n] ;
char Verb2[n] ;
if ( (Verb2[cnt-3] != 'e') && (Verb2[cnt-2] != 'e') )

Surely the last expression should be 'r' and the && should be ||. As
it reads now, the verb etre will pass your test.
a typo mistake and i didn't notice it on execution as i quickly check
with expected entries (verbe that end with e and r : chanter, penser,
trouver...
Good remark for && that should be ||...

It's nice to put out the error message but then you process the data
anyway as if it were acceptable input.
I believe a do-while loop will be better here.

Are you sure there are no 19 letter verbs?
95% sure. A resizable array would do fine. I'm currently learning
stdlib - malloc, calloc, realloc ...
for (i = 0, j = 0; i < sizeof pro / sizeof pro[0], i < sizeof term / sizeof term[0]; i ++)

First, can the two quotients ever be different?
I don't know at all how this code works. I got it from Pete's post/
reply earlier in this discussion. I take it as it is, i guess if i
keep on coding, sooner or later i'll understand

Second, are you aware that the comma operator discards the results of
the left operand? Therefore, sizeof pro takes no part in determining
if the loop should terminate. If you really need to check both, you
probably want the logical and (&&) operator.
If i understand well ; "...i < sizeof pro / sizeof pro[0], i < sizeof
term / sizeof term[0]..." --- "...i < sizeof term / sizeof term[0]" is
the taken into consideration alone? As this code as it is, is from
Pete earlier in this post, I can't tell much. See if he still reads
posts in this discussion.

Unfortunately, this object does not exist.

Neither does this one.
What object ? There are 2 distinct code and both works indepentantly
from the other. Variable names slighlty change "verb" is used in one
and "Verb" is used in the other one.

You did the if right but you still process the invalid data.
The last iteration invokes undefined behavior. Do you mean i < 8 is not right ? Earlier was declared Conju2 Conju
[7]. This declaration means there are 8 values if zero is a value.
This is quite in computing, I have seen it with vba...

Thanks for this review,

Pascal
 
B

bpascal123

The worst possible result of undefined behavior is that the program
behaves just as you expect it to. That doesn't mean you were lucky;
it means the error will be more difficult to track down -- until
it goes bad at exactly the worst possible moment.

(I'm basing this just on Barry's comment -- for which, BTW, you
deleted the attribution line. I haven't studied your code.)

--
Keith Thompson (The_Other_Keith) (e-mail address removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Hi Keith,

My last post is a reply to Barry's comment. There, i mention the code
which i think has undefined behavior. Barry didn't say much about it
so i could only guess where would this would be. for ( i = 0 ; i < 8 ; i++ )
printf("\n%s%s%s", Conju.Pro, verb2, Conju
.Term) ;

The code is in fourth post earlier in this current discussion page.

Thanks,

Pascal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top