Can C do it ?

B

bpascal123

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-

2° Would using a structure be more suitable?

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-
I get for the last part : warning: assignment makes integer from
pointer without a cast

I know it should be 'a' and 'b' but i really need "ab", "cd" ...
 
J

jacob navia

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.
I get for the last part : warning: assignment makes integer from
pointer without a cast

Sure, the compiler is completely confused. It understands
that you want to store some part of the address of the
"ab" character string into the first char of pstr.
I know it should be 'a' and 'b' but i really need "ab", "cd" ...

hint:

pstr[0] = 'a'
pstr[1] = 'b';
pstr[2] = 'c';
pstr[3] = 'd';

see?

You need 4 characters space to store "abcd". Isn't C wonderful?
 
J

James Kuyper

Hi,

I'd like to know if it would be possible to store constant string in
an array. ...

Yet, nowhere in your message do you make any use of the keyword 'const'.
I've inserted that keyword where I think it would be needed to match the
above description.
... I'd first like to avoid pointers so i can see how far we go
without pointers.

Trying to avoid pointers is pointless and nearly impossible in C. Any
time you call a function by name, the name of the function is
automatically converted into a pointer to the function. Any time you use
an lvalue of array type (which includes most used of string literals
except as initializers for a char array), it is automatically converted
into a pointer to the first element of the array. Trying to use C
without pointers is like trying to use English without the letter 'e'.

You can write C code that doesn't declare any pointer variables, and
such code can even be pretty useful; but you're still crippling yourself
as a C programmer by avoiding pointers.
Example :

-o-
char str[8] ;

char str[0] = "ab" ;

This defines str as an array of char (which is a constraint violation
(6.7p3), because str has already been defined in the same scope and same
name space) of length 0 (which is also a constraint violation
(6.7.5.2p1), the length of an array must always be >0).
char str[1] = "cd" ;
char str[7] = "op" ;

Those both violate 6.7p3, but at least they don't violate 6.7.5.2p1.
-o-

2° Would using a structure be more suitable?

I'm not sure what you actually meant by the first section, and you don't
give any details about what kind of structure you're thinking about.
However, I can say, with absolute certainty, that which of the two
approaches is the better one to use depends entirely upon how you intend
to use it.
3° What about a 2 dimensional array (even if it's a pain in c, with a
good algorithm behind, it should go through)...

This isn't too painful:

const char str2D[8][3] = {"ab", "cd", "", "", "", "", "", "op"};

The nastiest part is the '3'; you need to make that dimension long
enough to hold the longest string you intend to put in this array;
unlike the first dimension of the array, C doesn't provide a way of
automatically setting the remaining dimensions of an array to match the
length of the initializers.
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-
I get for the last part : warning: assignment makes integer from
pointer without a cast

That's perfectly correct. The string literal "ab" causes a piece of
memory three bytes long to be set aside to hold the char values 'a',
'b', and '\0'. The string literal itself is automatically converted into
a pointer to the location where those chars are stored. Then you attempt
to store that pointer value into a char, which is an integer type, not a
pointer type.

If you can overcome your fear of pointers, what you want to do might
correspond to the following:

const char *str1D[8] = {"ab", "cd", NULL, NULL, NULL, NULL, NULL, "op"};

In C99, there's a new feature called "designated initializers" that can
simplify that definition, making it closer to the spirit of your
original code:

const char *str1D[8] = {"ab", "cd", [7] = "op"};
 
B

Barry Schwarz

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.

You are going to need to be more specific.

Do you have a constant string that you want to copy into an
array? (Probably not since otherwise you could just strcpy it into
the array.)

Do want the string to be in an array that is constant so it
can never be changed? (Since you cannot assign to a const object, you
would have to initialize the array at the point where it is defined..)
Example :

-o-
char str[8] ;

char str[0] = "ab" ;

This code contributes nothing but confusion to the discussion since it
attempts to assign a value with pointer type to an object of char
type.
char str[1] = "cd" ;
...
char str[7] = "op" ;
-o-

2° Would using a structure be more suitable?

In what way would a structure rather than an array change your
question?
3° What about a 2 dimensional array (even if it's a pain in c, with a
good algorithm behind, it should go through)...

Why would you want a 2D array to hold a single string? What about 2D
arrays do you find painful?
4° And at last, if pointers were unvoidable would it be like this ?

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

How does this relate to your need for the string to be constant?
pstr[0] = "ab";

This code is just as broken and for the same reason.
pstr[1] = "cd" ;
-o-
I get for the last part : warning: assignment makes integer from
pointer without a cast

And this surprises you why?
I know it should be 'a' and 'b' but i really need "ab", "cd" ...

Start at the beginning. How many strings do you have? Is the number
known at compile time? Are the values of the strings known at compile
time? If not, at what point in time are the string values fixed so
that you need to treat them as constant for the remainder of the
program? It may help to consider that there is difference between a
constant pointer and a pointer to constant.
 
K

Keith Thompson

I'd like to know if it would be possible to store constant string in
an array.

Certainly:

char greeting[] = "hello";

But judging by your code that follows, I don't think that's what you
have in mind.
I'd first like to avoid pointers so i can see how far we go
without pointers.

If you're dealing with arrays, you're almost certainly using pointers,
at least implicitly. But you can use indexing operations without
necessarily thinking about the pointers behind the scenes.
Example :

-o-
char str[8] ;

This declares str as an array of 8 chars.
char str[0] = "ab" ;
char str[1] = "cd" ;
...
char str[7] = "op" ;

You're declaring str again, which I presume isn't what you had in
mind; you can't declare multiple objects of the same name in the same
scope. I'm really not sure what you're trying to do here.
-o-

2° Would using a structure be more suitable?

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

With the information you've given us so far, I can't tell.
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-
I get for the last part : warning: assignment makes integer from
pointer without a cast

Right, because pstr[0] is a char and "ab", after conversion, is a
char*. You can't store a char* in a char.
I know it should be 'a' and 'b' but i really need "ab", "cd" ...

Ok -- and what exactly do you want to do with them?

Take a look at this:

#include <stdio.h>
int main(void)
{
const char *arr[] = { "ab", "cd", "ef", "gh", "ij" };
int i;
for (i = 0; i < sizeof arr / sizeof arr[0]; i ++) {
puts(arr);
}
return 0;
}
 
B

bpascal123

From your answers, here are more infos

This is an application from a tutorial in French...if you have some
French language skills you could understand. Skills in German,
Spanish, Italian should help too since it's about a simple verb
conjugation.

In French like in English, the end of a verb is a variable that is
link (or let say that "points" to another variable ; the pronoun ... )

Just for info ; In French, verb are divided into 3 groups. This rule
only applies to verbs that end with "er" like below chantER... So in
the program the radical : "chant" has to be taken away.

Example :

English x French
x
To sing x Chanter
---------- x -------------------------------------
x Pro[9] Verb+ Term[9]
x
I sing x Je chant + e => chante
You sing x Tu chant + es => chantes
He sings x Il chant + e => chante
She sings x Elle chant + e => chante
It sings x Ca chant + e => chante
We sing x Nous chant + ons => chantons
You sing x Vous chant + ez => chantez
They sing x Ils chant + ent => chantent
x Elles chant + ent => chantent

This seems complete but it would be more difficult to give an
explanation in English since you don't have as many variables with
syntax (lucky you!).

As you can see and I realize now, Pro[9] and Term[9] have different
string sizes and they should always match each other (so they should
be incremented together Pro with Term)

Pro[0] = "Je"
Pro[3] = "Elle"
....
Term[5] = "ons"
Term[6] = "ez"
....

----------------
In another words : how i see this
----------------
Array of string Pronoun[9] = "Je" "Tu" "Il" ...
Array of string Term[9] = "e" "es" "e" ...
Simple string for Verb
Simple string for Shortverb
integer i for loop
Array of string that will host Pro + ' ' + "Verb" + Term

Enter a string
Read Verb

Check if input is a string that ends with 'e' 'r' '\0'
Replace in "Shortverb" 'e' with '\0'

print "result : "Verb" " and newline

For i = 0 ; i <= Len(Shortverb) ; i++
Concatenate and print Pro + ' ' + "Shortverb" + Term and newline

----------------

Result :

Je chante
Tu chantes
Il chante
....
Vous chantez
....

--------------


Even if i'll be doing very basic stuff for a while, I'd like not to
rely on pointer. As an accountant, learning to deal work with strings
and arrays can be helpful. I understand vba might be best for this,
however i'm not sure. I guess you'll wonder why i'm not learning vba
instead? This is because I first think C has more to offer in the
futur and makes it easier to get involved in web development or os
applications... and at last because of objects, learning vba requires
some resources to practice such as big data sheets or workbooks data
templates... With "C" i can start from scratch like now.

If you can help but plz keep it as simple as you can (i haven't
learned sizeof and what it does yet... i 'll get more on this as soon
as i can,

Thanks
Pascal
 
B

bartc

I sing x Je chant + e => chante
You sing x Tu chant + es => chantes
He sings x Il chant + e => chante
She sings x Elle chant + e => chante
It sings x Ca chant + e => chante
We sing x Nous chant + ons => chantons
You sing x Vous chant + ez => chantez
They sing x Ils chant + ent => chantent
x Elles chant + ent => chantent
For i = 0 ; i <= Len(Shortverb) ; i++
Concatenate and print Pro + ' ' + "Shortverb" + Term and newline


If you want to avoid (explicit) pointers, try this:

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

#define wordmax 32

int main(void) {

char pro[wordmax][9] =
{"je","tu","il","elle","ca","nous","vous","ils","elles"};
char term[wordmax][9] = {"e","es","e","e","ons","ez","ent","ent"};
char verb[wordmax] = "chant";
char result[wordmax];
int i;

for (i=0; i<sizeof pro[0]; ++i) {
strcpy(result,pro);
strcat(result,"\t");
strcat(result,verb);
strcat(result,term);
puts(result);
}

}

It works by using fixed length char arrays (of size 32 here, but it can be
anything) containing the strings (each of length 0 to 31 characters, plus
the terminator.

In the main loop, a single printf() would have sufficed, but this
demonstrates some string manipulation.
 
E

Eric Sosman

Hi,

I'd like to know if it would be possible to store constant string in
an array.

Yes.
I'd first like to avoid pointers so i can see how far we go
without pointers.

As soon as you do anything at all with an array other than
apply the sizeof operator to it, you're using pointers. You
may not see them, but they're there.
Example :

-o-
char str[8] ;

Declares an array of eight modifiable characters.
char str[0] = "ab" ;

Tries to declare an array of zero characters, which causes
the compiler to emit a diagnostic message because C doesn't have
zero-sized objects. Also tries to initialize those non-existent
array elements to contain the two characters 'a' and 'b'; since
two characters won't fit in zero spaces this makes no sense.
char str[1] = "cd" ;

Declares an array of one modifiable character, but then
tries to initialize that one character to hold two character
values 'c' and 'd'. Since two characters don't fit in one
space, this makes no sense.
...
char str[7] = "op" ;

Declares an array of seven modifiable characters.
Initializes the first two to the values 'o' and 'p', and
the remaining five to zero (not '0').
-o-

2° Would using a structure be more suitable?

For what? What are you trying to do? I'm unable to
discern your purpose from the examples given.
3° What about a 2 dimensional array (even if it's a pain in c, with a
good algorithm behind, it should go through)...

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

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

Declares an array of eight modifiable characters. Also
declares a pointer-to-char and initializes it to point at the
array's first element.
pstr[0] = "ab";

Causes a nameless three-character array to be created
somewhere, containing 'a', 'b', and zero (not '0'). The array
is not "unmodifiable" in a formal sense, but any attempt to
modify it produces undefined behavior.

Then creates a pointer to the first character of that array
(the 'a') and tries to store the pointer in the thing pstr points
at. That thing is a char -- the first char in your eight-element
array -- and since a pointer-to-char is not the same thing as a
char, the attempted assignment makes no sense and the compiler
emits a diagnostic message.
pstr[1] = "cd" ;

The identities of the characters in the new nameless array
are different, and the attempted assignment is to the eight-char
array's second slot instead of its first, but otherwise it's
like the earlier attempt: Nonsensical and diagnostic-generating.
-o-
I get for the last part : warning: assignment makes integer from
pointer without a cast

I know it should be 'a' and 'b' but i really need "ab", "cd" ...

What are you trying to do?
 
A

Amandil

Example :

-o-
char str[8] ;

Others have pointed out the contradiction between what you do here and
what you do immediately afterwards.
char str[0] = "ab" ;
char str[1] = "cd" ;
...
char str[7] = "op" ;

What I imagine you're trying to do could be conceivable in a higher-
level language as attempting to do:

char str[16]; /* Note larger size, 16 letters */
str[0,1] = ['a','b']; /* Not legal in in C */
str[2,3] = ['c','d'];
...
str[14,15] = ['o'.'p'];

....and you end up with str[] containing "abcdefghijklmnop".
Well, not really, because in C, the above string won't fit into str
[16]: remember that "..." requires a NUL ('\0') at the end.

2° Would using a structure be more suitable?

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 ?

Problem: C does not have a native string type. When you try to copy
more than one character at a time, you find that you can't. The
easiest way to accomplish this is by calling strcpy() - which, alas
for you, has as it's arguments two char pointers. C++, which also does
not have a native string type, has a standard string class which,
through operator-overloading,
can be used almost as if it were a native type.

What it seems you are trying to do is add "ab" + "cd" to get "abcd".
If the array containing "ab" is long enough (in this case, at least
char[5]) then you can use strcat(). If the strings you have are of
constant size (I think that's what you meant by saying "constant
strings"), then you might be able to use
strcpy(str, "ab");
strcpy(str+2, "cd");
strcpy(str+4, "ef");
which will save the nanoseconds strcat() spends to find the end of the
first string.

To conclude: to do what you are doing in C requires the use of
pointers. Even a 2-D array won't save you the work required to copy
more than 1 datum at a time.

Using a struct would be very limiting:
struct two_char {
char a, b;
} str[8];

You would still need two assignments for two characters.
str[0].a = 'a', str[0].b = 'b';
str[1].a = 'c', str[1].b = 'd';
etc.
The best I can come up with is (after the above declaration):
struct two_char yada = {'o', 'p'};
str[7] = yada; /* copying a struct /is/ possible */

But (1) you're limited to 2 chars at a time, any more would require a
new struct; and (2) the format "... = {'a', 'b'} can only be used
during initialization, not during assignment.

I may have given you enough information to use or misuse as you will.
But remember, if you misuse it terribly enough, demons /will/ fly out
of your nose. If it doesn't happen on its own, certain members of
c.l.c will visit you and shove the demons into your nose just to make
them fly out. You have been warned ;)

Marty Amandil

-- <Insert your favorite humorous sign-off here>
 
J

jameskuyper

Amandil said:
On Jul 29, 7:56 pm, "(e-mail address removed)"
char str[8] ;

Others have pointed out the contradiction between what you do here and
what you do immediately afterwards.
char str[0] = "ab" ;
char str[1] = "cd" ;
...
char str[7] = "op" ;

What I imagine you're trying to do could be conceivable in a higher-
level language as attempting to do:

char str[16]; /* Note larger size, 16 letters */
str[0,1] = ['a','b']; /* Not legal in in C */
str[2,3] = ['c','d'];
...
str[14,15] = ['o'.'p'];


Actually, I think what he's trying to do (but can't do in C without
overcoming his phobia about pointers) is more like the following:

const char *str[8];

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

Notice the syntax is very similar to what he actually wrote; but the
small syntactic differences turn meaningless code into correct code.
 
B

bartc

bartc said:
I sing x Je chant + e => chante
You sing x Tu chant + es => chantes
He sings x Il chant + e => chante
She sings x Elle chant + e => chante
It sings x Ca chant + e => chante
We sing x Nous chant + ons => chantons
You sing x Vous chant + ez => chantez
They sing x Ils chant + ent => chantent
x Elles chant + ent => chantent
For i = 0 ; i <= Len(Shortverb) ; i++
Concatenate and print Pro + ' ' + "Shortverb" + Term and newline


If you want to avoid (explicit) pointers, try this:

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

#define wordmax 32

int main(void) {

char pro[wordmax][9] =
{"je","tu","il","elle","ca","nous","vous","ils","elles"};
char term[wordmax][9] = {"e","es","e","e","ons","ez","ent","ent"};
char verb[wordmax] = "chant";
char result[wordmax];
int i;

for (i=0; i<sizeof pro[0]; ++i) {
strcpy(result,pro);
strcat(result,"\t");
strcat(result,verb);
strcat(result,term);
puts(result);
}

}


The rows/columns of the arrays are mixed up (which is quite common for me).
The declarations should be:

char pro[9][wordmax]...
char term[9][wordmax]...

And the for-loop is simplest just counting from 0 to <9.

However both versions work because the pronouns and terminations are all
less than 9 characters, and the for-loop was a fluke.
 
B

bpascal123

Example :
-o-
char str[8] ;

Others have pointed out the contradiction between what you do here and
what you do immediately afterwards.
char str[0] = "ab" ;
char str[1] = "cd" ;
...
char str[7] = "op" ;

What I imagine you're trying to do could be conceivable in a higher-
level language as attempting to do:

    char str[16];       /* Note larger size, 16 letters */
    str[0,1] = ['a','b'];   /* Not legal in in C */
    str[2,3] = ['c','d'];
    ...
    str[14,15] = ['o'.'p'];

...and you end up with str[] containing "abcdefghijklmnop".
Well, not really, because in C, the above string won't fit into str
[16]: remember that "..." requires a NUL ('\0') at the end.
2° Would using a structure be more suitable?
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 ?

Problem: C does not have a native string type. When you try to copy
more than one character at a time, you find that you can't. The
easiest way to accomplish this is by calling strcpy() - which, alas
for you, has as it's arguments two char pointers. C++, which also does
not have a native string type, has a standard string class which,
through operator-overloading,
can be used almost as if it were a native type.

What it seems you are trying to do is add "ab" + "cd" to get "abcd".
If the array containing "ab" is long enough (in this case, at least
char[5]) then you can use strcat(). If the strings you have are of
constant size (I think that's what you meant by saying "constant
strings"), then you might be able to use
    strcpy(str, "ab");
    strcpy(str+2, "cd");
    strcpy(str+4, "ef");
which will save the nanoseconds strcat() spends to find the end of the
first string.

To conclude: to do what you are doing in C requires the use of
pointers. Even a 2-D array won't save you the work required to copy
more than 1 datum at a time.

Using a struct would be very limiting:
struct two_char {
   char a, b;

} str[8];

You would still need two assignments for two characters.
    str[0].a = 'a', str[0].b = 'b';
    str[1].a = 'c', str[1].b = 'd';
   etc.
The best I can come up with is (after the above declaration):
struct two_char yada = {'o', 'p'};
str[7] = yada;    /* copying a struct /is/ possible */

But (1) you're limited to 2 chars at a time, any more would require a
new struct; and (2) the format "... = {'a', 'b'} can only be used
during initialization, not during assignment.

I may have given you enough information to use or misuse as you will.
But remember, if you misuse it terribly enough, demons /will/ fly out
of your nose. If it doesn't happen on its own, certain members of
c.l.c will visit you and shove the demons into your nose just to make
them fly out. You have been warned ;)

Marty Amandil

-- <Insert your favorite humorous sign-off here>

Nice! I now need to close my book (snif) and try to implement what you
have written. Because of this over work, i'm blowing out so strong not
many demons like "redundant" tv dish shows will remain for a while :)

Other replies above are very useful too.

Thanks for this.

Pascal
 
N

Nick Keighley

I     sing      x      Je         chant + e        => chante
You   sing      x      Tu         chant + es       => chantes
He    sings     x      Il         chant + e        => chante
She   sings     x      Elle       chant + e        => chante
It    sings     x      Ca         chant + e        => chante
We    sing      x      Nous       chant + ons      => chantons
You   sing      x      Vous       chant + ez       => chantez
They  sing      x      Ils        chant + ent      => chantent
               x      Elles      chant + ent      => chantent
For i = 0 ; i <= Len(Shortverb) ; i++
Concatenate and print Pro + ' ' + "Shortverb" + Term and newline


If you want to avoid (explicit) pointers, try this:

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

#define wordmax 32

int main(void) {

char pro[wordmax][9] =
{"je","tu","il","elle","ca","nous","vous","ils","elles"};
char term[wordmax][9] = {"e","es","e","e","ons","ez","ent","ent"};[/QUOTE]

I know the OP said he wanted to avoid explicit pointers, but
it seems so much neater to use them

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

[just curious, what's the "ca" thingy? (I failed french)]

this makes sense because 'j' is a character (a char in C terminology)
and "je" is a string, that is it is a pointer to a contiguous sequence
of
chars. 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. But will go in
pointer-to-char variable (or an array of them).

char verb[wordmax] = "chant";

char *verb = "chant";
char result[wordmax];
int i;

for (i=0; i<sizeof pro[0]; ++i) {
 strcpy(result,pro);
 strcat(result,"\t");
 strcat(result,verb);
 strcat(result,term);
 puts(result);

}


# define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0])

for (i = 0; i < ARRAY_SIZE (pro); i++)
printf ("%s s%s\n", pro, verb, term[i});

In the main loop, a single printf() would have sufficed, but this
demonstrates some string manipulation.

I only read this after I wrote the code above. I think the printf()
is neater.

--
Nick Keighley

10.3. Transput declarations
{ "So it does!" said Pooh, "It goes in!"
"So it does!" said Piglet, "And it comes out!"
"Doesn't it?" said Eeyore, "It goes in and out like
anything,"
Winnie-the-Pooh, A.A. Milne.}
From the "Revised Report on the Algorithmic Language ALGOL 68"
 
B

bpascal123

[just curious, what's the "ca" thingy? (I failed french)]

ca or well written : ça, means it or that ... here :

he sings (il chante),
seh sings(elle chante),
it sings (ça chante) : "ça" is aimed mostly at artefacts (ex.: it's
moving = ça bouge) or when "ça" as a pronoun of a verb is used by an
adult on other things like a person or an animal, it's to express
quite a bad though or make a negative mockery in a specific context
(that thing sings or that thing knows how to sing = ça chante ou ça
sait chanter...) and it can be used by baby childs just for example
because he can't yet make distinctions between animals and toys.

Pascal
http://www.accreditation.freesurf.fr/e.teachyourselfengfr/english/ensfreng0..html
 
B

bpascal123

[just curious, what's the "ca" thingy? (I failed french)]

ca or well written : ça, means it or that ... here :

he sings (il chante),
seh sings(elle chante),
it sings (ça chante) : "ça" is aimed mostly at artefacts (ex.: it's
moving = ça bouge) or when "ça" as a pronoun of a verb is used by an
adult on other things like a person or an animal, it's to express
quite a bad though or make a negative mockery in a specific context
(that thing sings or that thing knows how to sing = ça chante ou ça
sait chanter...) and it can be used by baby childs just for example
because he can't yet make distinctions between animals and toys.

Pascal
http://www.accreditation.freesurf.fr/e.teachyourselfengfr/english/ensfreng0..html
 
B

bartc

Nick said:
I sing x Je chant + e => chante ....
For i = 0 ; i <= Len(Shortverb) ; i++
Concatenate and print Pro + ' ' + "Shortverb" + Term and
newline
[/QUOTE]
char *pro[] =
{"je","tu","il","elle","ça","nous","vous","ils","elles"};
char *term[] = {"e","es","e","e","ons","ez","ent","ent"};
for (i=0; i<sizeof pro[0]; ++i) {
strcpy(result,pro);
strcat(result,"\t");
strcat(result,verb);
strcat(result,term);
puts(result);

}


# define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0])

for (i = 0; i < ARRAY_SIZE (pro); i++)
printf ("%s s%s\n", pro, verb, term[i});

In the main loop, a single printf() would have sufficed, but this
demonstrates some string manipulation.

I only read this after I wrote the code above. I think the printf()
is neater.


sprintf() is also useful for simple string copy/concatenate, if the result
needs to be passed elsewhere:

sprintf (result,"%s %s%s", pro, verb, term);
puts(result);

(and 'verb' should be 'verbroot' or 'verbstem' really).
 
B

bpascal123

because he can't yet make distinctions between animals and toys.


The definition is not over and in fact seem a quite short.

I should add that "ça" pronounced a bit like "saw" could be used by
someone who has little knowledge in french (a bit like a baby). For
instance a tourist in France can show a leather coat jacket in a shop
and not know that the name in french is : "une veste en cuir" and ask
for the price :

How much does it cost or
How much does that cost ?... in french : Combien est-ce que ça coute ?
That one ? ... in french : Celui-là ?
No, this one. ... in french : Non, celui-ci - - - loop until the right
one :)

This is just to broaden the use of "ça" even if it's not the right
place, i think i'm done, sorry.
 
B

Ben Bacarisse

Nick Keighley said:
I know the OP said he wanted to avoid explicit pointers, but
it seems so much neater to use them

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

Yes. I have a string aversion to tutorials that suggest exercises
that are much better done with features not yet introduced. A small
amount of this is inevitable, but no one should be writing
string-based programs in C without a basic understanding of pointing
to (the start of) an array of characters, and the basic library
functions for manipulating them.

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.
 
B

bpascal123

because he can't yet make distinctions between animals and toys.


The definition is not over and in fact seem a quite short.

I should add that "ça" pronounced a bit like "saw" could be used by
someone who has little knowledge in french (a bit like a baby). For
instance a tourist in France can show a leather coat jacket in a shop
and not know that the name in french is : "une veste en cuir" and ask
for the price :

How much does it cost or
How much does that cost ?... in french : Combien est-ce que ça coute ?
That one ? ... in french : Celui-là ?
No, this one. ... in french : Non, celui-ci - - - loop until the right
one :)

This is just to broaden the use of "ça" even if it's not the right
place, i think i'm done, sorry.
 
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
 

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

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top