473,396 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pascal - C (2)

Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?

2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.

3) In Pascal I can "add" lines:

Line1 = 'File size:' + sSize + ' bytes.';

My solution:

strcpy(Line1, "File size:");
strcat(Line1, sSize);
strcat(Line1, " bytes.);

Again, I just wonder if there is a more simpler solution.

4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};

It works but in this case I'm certainly not happy with the solution.
Is there a better way?

Many thanks for any comment!
--
___
/ __|__
/ / |_/ Groetjes, Ruud Baltissen
\ \__|_\
\___| http://Ruud.C64.org
Nov 1 '08 #1
54 3091
Ruud wrote:
Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?
No, C does not have nested functions, although some compilers support
them as extensions.
2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
Sorry, no. One alternative is to use a regular expression library if
you have a lot of these.
3) In Pascal I can "add" lines:

Line1 = 'File size:' + sSize + ' bytes.';

My solution:

strcpy(Line1, "File size:");
strcat(Line1, sSize);
strcat(Line1, " bytes.);

Again, I just wonder if there is a more simpler solution.
Not in C.
4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};

It works but in this case I'm certainly not happy with the solution.
Is there a better way?
Don't use C. C does not have string objects, of arrays of char and
library functions to manipulate then.

If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string processing
and might be a better option.

--
Ian Collins
Nov 1 '08 #2
Ian Collins wrote:
Ruud wrote:
>Hallo allemaal,
3) In Pascal I can "add" lines:

Line1 = 'File size:' + sSize + ' bytes.';

My solution:

strcpy(Line1, "File size:");
strcat(Line1, sSize);
strcat(Line1, " bytes.);

Again, I just wonder if there is a more simpler solution.
Not in C.
That is nonsense

sprintf(Line1,"File size: %s bytes",sSize);

And you can save yourself transforming Size into a string with

sprintf(Line1,"File size: %d bytes",Size);
>
>4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};

It works but in this case I'm certainly not happy with the solution.
Is there a better way?
Don't use C. C does not have string objects, of arrays of char and
library functions to manipulate then.
If you do not know enough C please do not use this group.

The above can be done with

sprintf(str1,"%s%c",Str2,Str3[5]);

If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string processing
and might be a better option.
C has problems with strings but it is usable. Other languages have other
(bigger) problems

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 1 '08 #3
Ruud wrote:
Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?

2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
That one is simple enough
3) In Pascal I can "add" lines:

Line1 = 'File size:' + sSize + ' bytes.';

My solution:

strcpy(Line1, "File size:");
strcat(Line1, sSize);
strcat(Line1, " bytes.);

Again, I just wonder if there is a more simpler solution.
Yes:
sprintf(Line1,"File size: %s bytes",sSize);

And you can save yourself transforming Size into a string with

sprintf(Line1,"File size: %d bytes",Size);
>
4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};

It works but in this case I'm certainly not happy with the solution.
Is there a better way?
Yes.
The above can be done with

sprintf(str1,"%s%c",Str2,Str3[5]);

Many thanks for any comment!
--
___
/ __|__
/ / |_/ Groetjes, Ruud Baltissen
\ \__|_\
\___| http://Ruud.C64.org


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 1 '08 #4
On 1 Nov 2008 at 22:23, jacob navia wrote:
Ian Collins wrote:
>Not in C.

That is nonsense

sprintf(Line1,"File size: %s bytes",sSize);

And you can save yourself transforming Size into a string with

sprintf(Line1,"File size: %d bytes",Size);
Yes. In fact, many implementations also provide an asprintf() function
in their standard library, which allocates memory for Line1 with malloc,
saving you the trouble of working out the size of the buffer needed and
eliminating possible overflows if you miscalculate.

Nov 1 '08 #5
Antoninus Twink wrote:
On 1 Nov 2008 at 22:23, jacob navia wrote:
>Ian Collins wrote:
>>Not in C.
That is nonsense

sprintf(Line1,"File size: %s bytes",sSize);

And you can save yourself transforming Size into a string with

sprintf(Line1,"File size: %d bytes",Size);

Yes. In fact, many implementations also provide an asprintf() function
in their standard library, which allocates memory for Line1 with malloc,
saving you the trouble of working out the size of the buffer needed and
eliminating possible overflows if you miscalculate.
Yes, that would be an even better alternative.

I answered so quickly because I was astonished that somebody could answer

"Not in C"

to such elemntary question!
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 1 '08 #6
jacob navia wrote:
Ian Collins wrote:
>>>
Don't use C. C does not have string objects, of arrays of char and
library functions to manipulate then.

If you do not know enough C please do not use this group.
Why do you have to insult everyone?
>If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string processing
and might be a better option.

C has problems with strings but it is usable. Other languages have other
(bigger) problems
So what part of my statement do you disagree with? A pair of pliers has
problems but is usable for undoing bolts, would you use them if you had
a spanner that fitted?

Your C tunnel vision appears to have blinded you the the existence of
other languages.

--
Ian Collins
Nov 1 '08 #7
Ian Collins wrote:
jacob navia wrote:
>Ian Collins wrote:
>>Don't use C. C does not have string objects, of arrays of char and
library functions to manipulate then.
If you do not know enough C please do not use this group.
Why do you have to insult everyone?
I am not insulting you. But failing to point
to sprintf as an obvious solution for that problem seems (to me)
a serious problem with the basics of the language.

I do not see why stating "you do not know enough C"
is an insult!

Besides I would have never said that if you wouldn't have
started with that arrogant

"Don't use C"

stuff.
>>If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string processing
and might be a better option.
C has problems with strings but it is usable. Other languages have other
(bigger) problems
So what part of my statement do you disagree with?
"Don't use C"

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 1 '08 #8
jacob navia wrote:
Ian Collins wrote:
>jacob navia wrote:
>>Ian Collins wrote:
>>>If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string
processing
and might be a better option.

C has problems with strings but it is usable. Other languages have other
(bigger) problems
So what part of my statement do you disagree with?

"Don't use C"
But why would you use C for string manipulation when there better
alternatives?

--
Ian Collins
Nov 1 '08 #9
Ruud <Ru************@apg.nlwrites:
2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
In this case, yes. There are macros in <ctype.hfor testing whether a
character is a member of various classes. This has the added advantage
of being more portable, in case you should find yourself using a
character set where 'A','B','C','D','E','F' don't occur contiguously.
So a better way to write the above might be

#include <ctype.h>
/* ... */
if (isxdigit(c)) {
/* c is hexadecimal */
}

There are others, such as isalpha(), isdigit(), isspace(), isupper(),
etc. See your compiler's documentation or the C standard for a complete
list.

As a side note, some compilers (such as gcc) support an extension that
would let you do

switch (c) {
case 'A' ... 'F':
case '0' ... '9':
/* c is hexadecimal */
}

but that suffers the same character-set dependency as what you wrote
above, and is non-standard, and isn't really much simpler to read or write.
Nov 1 '08 #10
Ian Collins wrote:
jacob navia wrote:
>Ian Collins wrote:
>>jacob navia wrote:
Ian Collins wrote:
If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string
processing
and might be a better option.
>
C has problems with strings but it is usable. Other languages have other
(bigger) problems

So what part of my statement do you disagree with?
"Don't use C"
But why would you use C for string manipulation when there better
alternatives?
For many reasons:

1) C is a simple language easily available
2) Languages like perl/python have better string manipulation
primitives but have other problems like performance,
and availability.
3) If you use the pcre library (distributed with lcc-win) you have
all the power of perl in C without the problems associated
with perl.
4) Extensions to C like those proposed by lcc-win make the
problems with raw C strings disappear.

jacob
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 1 '08 #11
In article <ba**********************************@f37g2000pri. googlegroups.com>,
Ruud <Ru************@apg.nlwrote:
Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?
Not in standard C. Some compilers have an extension to allow this.
2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
if (isxdigit(c)) ...

There are various ways to represent sets as bit arrays in C. None are officially
sanctified as a set type.
3) In Pascal I can "add" lines:

Line1 = 'File size:' + sSize + ' bytes.';

My solution:

strcpy(Line1, "File size:");
strcat(Line1, sSize);
strcat(Line1, " bytes.);

Again, I just wonder if there is a more simpler solution.
The standard C library <string.his not really intended to deal with
dynamickally resized strings. There are numerous libraries and implementation
that do all this for you. For example, Tcl has its Tcl_DString. Other solutions
are available.
4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};

It works but in this case I'm certainly not happy with the solution.
Is there a better way?
As above. You can layer on top of the standard library.

--
I'm not even supposed to be here today.

I ASSURE YOU WE'RE OPEN!
Nov 1 '08 #12
jacob navia wrote:
Ian Collins wrote:
>>>
But why would you use C for string manipulation when there better
alternatives?

For many reasons:

1) C is a simple language easily available
2) Languages like perl/python have better string manipulation
primitives but have other problems like performance,
and availability.
I'll concede performance, although scripting language string
manipulation is well optimised. Availability is debatable, requirements
for lots of string processing tend to be on platforms where other
languages are available.
3) If you use the pcre library (distributed with lcc-win) you have
all the power of perl in C without the problems associated
with perl.
4) Extensions to C like those proposed by lcc-win make the
problems with raw C strings disappear.
lcc-win is way less portable than most, if not all, scripting languages.

--
Ian Collins
Nov 1 '08 #13
Ian Collins wrote:
jacob navia wrote:
>Ian Collins wrote:
>>But why would you use C for string manipulation when there better
alternatives?
For many reasons:

1) C is a simple language easily available
2) Languages like perl/python have better string manipulation
primitives but have other problems like performance,
and availability.

I'll concede performance, although scripting language string
manipulation is well optimised. Availability is debatable, requirements
for lots of string processing tend to be on platforms where other
languages are available.
Well the language choice is maybe not only for string manipulation.
Other reasons are probably more important, we do not know what
application the OP has. Note that he is translating from Pascal to
C. Pascal is even worst for string manipulation than C since
libraries like PCRE regular expressions are not easily available,
and regular expressions at all are not easy to find in Pascal.

C + the PCRE library is a very good choice for string manipulation,
combining performance and power.
>3) If you use the pcre library (distributed with lcc-win) you have
all the power of perl in C without the problems associated
with perl.
4) Extensions to C like those proposed by lcc-win make the
problems with raw C strings disappear.
lcc-win is way less portable than most, if not all, scripting languages.
Maybe. But pcre is highly portable and can be used anywhere a
C compiler exists.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 2 '08 #14
Ruud wrote:
4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};
You can use strncat() to concatenate any number of characters from one
string to another. For this case you would use

strcpy(Str1, Str2);
strncat(Str1, &Str3[5], 1);

Observe that Str3[5] is a char, not a pointer to char, so you have to
take the address of it with & to pass it to strncat. This is the source
of the error you mentioned.
Nov 2 '08 #15
jacob navia wrote:
Ian Collins wrote:
>Ruud wrote:
.... snip ...
>>
>>It works but in this case I'm certainly not happy with the
solution. Is there a better way?

Don't use C. C does not have string objects, of arrays of char
and library functions to manipulate then.

If you do not know enough C please do not use this group.
Of course, if you are as knowledgeable as Jacob, and similarly
adept at avoiding off-topic messages (sarcasm) you can make such
foolish requests.

Ruud, go ahead and ask questions. It is one way to learn. A good
book, such as K&R II, would be helpful.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 2 '08 #16
jacob navia wrote:
Antoninus Twink wrote:
.... snip ...
>
>Yes. In fact, many implementations also provide an asprintf()
function in their standard library, which allocates memory for
Line1 with malloc, saving you the trouble of working out the
size of the buffer needed and eliminating possible overflows
if you miscalculate.

Yes, that would be an even better alternative.
Hardly, bearing in mind the fact that there is no such function as
'asprintf()' in the C standard, and that no code to implement it
has been proposed here. Twink is a known troll, whose primary
objective appears to be disruption of the newsgroup. Navia also
tends to be off-topic, but that appears to be largely due to
ignorance of the language combined with his refusal to listen.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 2 '08 #17
Ian Collins said:
Ruud wrote:
>Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?
No, C does not have nested functions, although some compilers support
them as extensions.
Right so far.
>
>2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
Sorry, no.
Why not at least tell him about:

if(isupper(c) || isdigit(c))

and

if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", c) != NULL)

neither of which is a precise match, but each of which might be used in
similar situations.

One alternative is to use a regular expression library if
you have a lot of these.
That seems like overkill to me.
>
>3) In Pascal I can "add" lines:

Line1 = 'File size:' + sSize + ' bytes.';

My solution:

strcpy(Line1, "File size:");
strcat(Line1, sSize);
strcat(Line1, " bytes.);

Again, I just wonder if there is a more simpler solution.
Not in C.
Um, of course there is.

sprintf(Line1, "File size: %d byte%s", sSize, bytes == 1 ? "" : "s");

Note the extra flexibility that C gives you.
>
>4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};

It works but in this case I'm certainly not happy with the solution.
Is there a better way?
Yes - sprintf can do this easily enough.

sprintf(Str1, "%s%c", Str2, Str3[5]);
>>
Don't use C.
Um, he asked for a better way to do this in C. Not using C doesn't count.
C does not have string objects,
True, but it has a string format which works just fine.
of arrays of char and library functions to manipulate then.
I'm not sure what you mean here (unless "of" is a typo for "just" or "only"
or "merely", but yes, C has arrays of char and library functions to
manipulate them. Good!
If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string processing
and might be a better option.
ROTFL! If you are doing a shedload of string manipulation, C is a far
better choice than Perl. That is, if you want it to finish some time.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 2 '08 #18
Richard Heathfield wrote:
>
Why not at least tell him about:

if(isupper(c) || isdigit(c))

and

if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", c) != NULL)
I don't know, must have been a bad hair day. Too many kids making too
much noise too early after too little caffeine.

--
Ian Collins
Nov 2 '08 #19
Richard Heathfield <rj*@see.sig.invalidwrites:
Ian Collins said:
>Ruud wrote:
>>Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?
No, C does not have nested functions, although some compilers support
them as extensions.

Right so far.
>>
>>2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
Sorry, no.

Why not at least tell him about:

if(isupper(c) || isdigit(c))

and

if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", c) != NULL)
Or, even better, isxdigit(). "(c >= 'A') && (c <= 'Z')" was a typo;
the original Pascal was looking for hexadecimal digits, not
alphanumerics. If you want to reject lowercase hex digits, you'll
need to write something like (isxdigit(c) && !islower(c)). If c is of
type char and there's any chance its value could be negative, you'll
need to convert it to unsigned char before passing it to one of the
is*() functions.

[...]
sprintf(Line1, "File size: %d byte%s", sSize, bytes == 1 ? "" : "s");

Note the extra flexibility that C gives you.
Yes, but you have to work a bit harder (than in, say, Perl) to manage
the memory.

[...]
>If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string processing
and might be a better option.

ROTFL! If you are doing a shedload of string manipulation, C is a far
better choice than Perl. That is, if you want it to finish some time.
That hasn't been my experience, but this is off-topic.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Nov 2 '08 #20
On Sun, 02 Nov 2008 06:54:51 +0000, Richard Heathfield wrote:
>If you are doing a lot of string manipulation, C might not be your best
choice. Scripting language like Perl are designed for string processing
and might be a better option.

ROTFL! If you are doing a shedload of string manipulation, C is a far
better choice than Perl. That is, if you want it to finish some time.
I remember what Leroy said about pascal. Now that Leroy is a big and rich
star, his criticism remains.

I think the dealbreaker is whether one plays fast and loose with data.

That's been popular. There has, however, been the anti-phenomenon of data
mining, which plays fast and loose with data until the *right one* comes
up.
--
George

Freedom itself was attacked this morning by a faceless coward, and freedom
will be defended.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
Nov 2 '08 #21
On 1 Nov 2008 at 23:07, jacob navia wrote:
Antoninus Twink wrote:
>Yes. In fact, many implementations also provide an asprintf() function
in their standard library, which allocates memory for Line1 with malloc,
saving you the trouble of working out the size of the buffer needed and
eliminating possible overflows if you miscalculate.

Yes, that would be an even better alternative.

I answered so quickly because I was astonished that somebody could answer

"Not in C"

to such elemntary question!
Yes, it's simply amazing what nonsense they talk.

Nov 2 '08 #22
On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <ja***@nospam.com>
wrote:
>Ruud wrote:
>Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?

2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.

That one is simple enough
Except for the fact that it doesn't work on an EBCDIC system.
--
Remove del for email
Nov 2 '08 #23
Barry Schwarz wrote:
On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <ja***@nospam.com>
wrote:
>Ruud wrote:
>>Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?

2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
That one is simple enough

Except for the fact that it doesn't work on an EBCDIC system.

yes. A better solution is ishexdigit()...
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 2 '08 #24
jacob navia wrote, On 02/11/08 09:56:
Barry Schwarz wrote:
>On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <ja***@nospam.com>
wrote:
>>Ruud wrote:
Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?

2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.

That one is simple enough

Except for the fact that it doesn't work on an EBCDIC system.

yes. A better solution is ishexdigit()...
You means isxdigit(). This, in my opinion, is simpler than the Pascal
solution.

The OP should note that whilst '0' to '9' are guaranteed to be in
sequence (allowing "c - '0'" to work as expected) there is no such
guarantee with letters in C. Since I'm guessing there will be a
conversion from character to number for a fully portable solution strchr
could well be useful.
static const char *xdigits = "0123456789ABCDEF";
char *pos = strchr("0123456789ABCDEF",toupper((unsigned char)c));
if (pos) { /* character found so was a hex digit */
digit = pos - xdigits;
}
else { /* not a hex digit */
}

In my opinion, for characters strchr is very close to "in" in Pascal.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 2 '08 #25
Hallo allemaal,
Many thanks for the massive response!
jacob navia wrote:
If you do not know enough C please do not use this group.
Then please be a good man and tell me what level I should have before
I can attend this group?
Chuck wrote:
Ruud, go ahead and ask questions.
Thank you very much for your support, Chuck!

A good book, such as K&R II, would be helpful.
The book isn't the problem, see next.
Richard wrote:
Why not at least tell him about:

if(isupper(c) || isdigit(c))

and

if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", c) != NULL)
The problem is not knowing all those available functions. And knowing
another language is a disavantage as well: instead of reading the book
line by line, one tends to look just at "how is this done in C".
And even reading the book line by line isn't a guarantee for success:
I justed searched the book "C in 21 days" for 'isdigit' and only found
one source file using this function. OTOH, this source file also
mentioned the function 'isspace' and this function does exactly what
one of my own made function does; detecting white space.

sprintf
Not mentioned at all "C in 21 days" :( Because 'printf' was well
explained, I never used the help function of Borland C to give it a
better look. I wish I had because I just did: I learned nothing new
about 'printf' but the page also mentioned 'sprintf' and many more
other functions.
Trent wrote:
strncat(Str1, &Str3[5], 1);
Here I have no excuse, it is mentioned very clearly in the book.
--
___
/ __|__
/ / |_/ Groetjes, Ruud Baltissen
\ \__|_\
\___| http://Ruud.C64.org

Nov 2 '08 #26
Ruud wrote:
Hallo allemaal,
Many thanks for the massive response!
jacob navia wrote:
>If you do not know enough C please do not use this group.
Then please be a good man and tell me what level I should have before
I can attend this group?
As you can see from my quotes, I do not told YOU that but to Ian
Collins. Please try to understand how quoting works.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 2 '08 #27
On Sun, 02 Nov 2008 01:28:00 -0700, Barry Schwarz wrote:
On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <ja***@nospam.com>
wrote:
>>Ruud wrote:
>>2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.

That one is simple enough

Except for the fact that it doesn't work on an EBCDIC system.
It will (after fixing 'Z' so that it reads 'F') work on ASCII end EBCDIC
systems. In theory, there could be other systems where it will fail. I
doubt there are any such systems in practise, though.
Nov 2 '08 #28
Ruud wrote:
Hallo allemaal,
During the conversion of my program from Pascal to C, I was more or
less able to find the C equivalent of most Pascal functions so far.
Only four gave me some real trouble. I solved them but it could be I
overlooked something.

1) In Pascal you can declare functions inside a function. AFAIK this
is not possible with C. Or am I wrong?
Inside a C function you can *declare* another function
but you cannot *define* one.
2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.
There are no built-in "set membership" facilities in C.
It's assumed that different kinds of sets call for different
kinds of representations -- bit mask, array of elements, array
of ranges, whatever -- and that you will code according to the
representation chosen rather than to the set abstraction.

For classifying characters, though, the Standard library
offers some functions you may find useful. In particular, the
<ctype.hheader declares two functions you can combine to make
the test shown in your example:

#include <ctype.h>
...
int ch = (unsigned char)(...);
if (isxdigit(ch) && !islower(ch)) ...
3) In Pascal I can "add" lines:

Line1 = 'File size:' + sSize + ' bytes.';

My solution:

strcpy(Line1, "File size:");
strcat(Line1, sSize);
strcat(Line1, " bytes.);

Again, I just wonder if there is a more simpler solution.
That works, assuming sSize is a string and Line1 is a
char[] array of sufficient size. An alternative that can be
convenient (especially if some of the data are not already
in string form) is to use sprintf().
4) In Pascal I can "add" just one character of another string:

Str1 = Str2 + Str3[5];

Unfortunately strcat(Str1, Str3[5]); doesn't work, I get an error
message. My solution:

Str4[0] = Str3[5];
Str4[1] = 0;
strcpy(Str1, Str2};
strcat(Str1, Str4};

It works but in this case I'm certainly not happy with the solution.
Is there a better way?
"Better" is a slippery word. There are certainly "other"
ways, such as

strcpy(Str1, Str2);
Str1[ strlen(Str2) ] = Str3[5];
Str1[ strlen(Str2) ] = '\0';

or

sprintf (Str1, "%s%c", Str2, Str3[5]);

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 2 '08 #29
Ruud wrote, On 02/11/08 12:11:
Hallo allemaal,
<snip>
>A good book, such as K&R II, would be helpful.

The book isn't the problem, see next.
Ah, but it could be! You would be well advised to get K&R2.
<snip>
I justed searched the book "C in 21 days" for 'isdigit' and only found
<snip>
Not mentioned at all "C in 21 days" :( Because 'printf' was well
<snip>

"C in 21 days" is *a* book, but what makes you think it is a *good*
book? K&R2 is an excellent (but not perfect) book and there are a few
others that generally get recommended here, but the book you have is not
one of them.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 2 '08 #30
On Sun, 2 Nov 2008 12:50:11 +0000 (UTC), Harald van D?k
<tr*****@gmail.comwrote:
>On Sun, 02 Nov 2008 01:28:00 -0700, Barry Schwarz wrote:
>On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <ja***@nospam.com>
wrote:
>>>Ruud wrote:
2) In Pascal there exists the "in" function. Example:

if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }

This can be translated like:

if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal

I just wonder if there is a more simpler solution.

That one is simple enough

Except for the fact that it doesn't work on an EBCDIC system.

It will (after fixing 'Z' so that it reads 'F') work on ASCII end EBCDIC
systems. In theory, there could be other systems where it will fail. I
doubt there are any such systems in practise, though.
On EBCDIC systems, a-f are also valid hex digits. The same is true on
Solaris systems. Even in standard C, the conversion specification "x"
produces a-f while"X" produces A-F. Surely each of the characters
produced either way is a valid hex character.

--
Remove del for email
Nov 2 '08 #31
jacob navia <ja***@nospam.comwrites:
Ruud wrote:
>Hallo allemaal,
Many thanks for the massive response!
jacob navia wrote:
>>If you do not know enough C please do not use this group.
>Then please be a good man and tell me what level I should have before
I can attend this group?

As you can see from my quotes, I do not told YOU that but to Ian
Collins. Please try to understand how quoting works.
I think he understood that. If your remark was intended only for Ian
Collins, you could have sent him e-mail. You seemed to be mandating
some minimum level of knowledge as a requirement for posting here;
surely such a rule would not apply only to Ian Collins. Ruud just
wanted to you clarify the rules.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Nov 2 '08 #32
Barry Schwarz <sc******@dqel.comwrites:
On Sun, 2 Nov 2008 12:50:11 +0000 (UTC), Harald van D?k
<tr*****@gmail.comwrote:
>>On Sun, 02 Nov 2008 01:28:00 -0700, Barry Schwarz wrote:
>>On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <ja***@nospam.com>
wrote:
Ruud wrote:
2) In Pascal there exists the "in" function. Example:
>
if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }
>
This can be translated like:
>
if ( ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))) .... // c is hexadecimal
>
I just wonder if there is a more simpler solution.

That one is simple enough

Except for the fact that it doesn't work on an EBCDIC system.

It will (after fixing 'Z' so that it reads 'F') work on ASCII end EBCDIC
systems. In theory, there could be other systems where it will fail. I
doubt there are any such systems in practise, though.

On EBCDIC systems, a-f are also valid hex digits. The same is true on
Solaris systems. Even in standard C, the conversion specification "x"
produces a-f while"X" produces A-F. Surely each of the characters
produced either way is a valid hex character.
Maybe the OP has some specific reason to accept only uppercase
letters. (Or maybe he just forgot about lowercase letters.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Nov 2 '08 #33
In article <ge**********@registered.motzarella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrote:

[Copying a single character into a string]
"Better" is a slippery word. There are certainly "other"
ways, such as

strcpy(Str1, Str2);
Str1[ strlen(Str2) ] = Str3[5];
Str1[ strlen(Str2) ] = '\0';
That last line looks wrong to me; I think you want to add 1 to
strlen(Str2) before you use it as an index into Str1.

If I were writing that code, I would probably use something like this
instead:
strcpy(Str1,Str2);
len=strlen(Str1);
Str1[len++]=Str3[5];
Str1[len++]='\0';

This is also a case where strncat's (generally confusing)
interpretation of its count argument turns out to be useful:
strcpy(Str1,Str2);
strncat(Str1,Str3+5,1);
(But be careful using this one in code that has to be maintained.)
dave

--
Dave Vandervies dj3vande at eskimo dot com
You are determined to martyr yourself on a nonexistent altar
An altar could be arranged.
--Mark McIntyre and Richard Heathfield in comp.lang.c
Nov 2 '08 #34
dj******@csclub.uwaterloo.ca.invalid wrote:
In article <ge**********@registered.motzarella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrote:

[Copying a single character into a string]
> "Better" is a slippery word. There are certainly "other"
ways, such as

strcpy(Str1, Str2);
Str1[ strlen(Str2) ] = Str3[5];
Str1[ strlen(Str2) ] = '\0';

That last line looks wrong to me; I think you want to add 1 to
strlen(Str2) before you use it as an index into Str1.
Right you are. Thanks.
If I were writing that code, I would probably use something like this
instead:
strcpy(Str1,Str2);
len=strlen(Str1);
Str1[len++]=Str3[5];
Str1[len++]='\0';

This is also a case where strncat's (generally confusing)
interpretation of its count argument turns out to be useful:
strcpy(Str1,Str2);
strncat(Str1,Str3+5,1);
(But be careful using this one in code that has to be maintained.)
... and now you need to tack on the terminating '\0'
that strncat() didn't give you. (We're both obviously
suffering from the effects of a 25-hour day, and besides:
Turnabout is fair play.)

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 2 '08 #35
jacob navia wrote:
Ruud wrote:
>jacob navia wrote:
>>If you do not know enough C please do not use this group.

Then please be a good man and tell me what level I should have
before I can attend this group?

As you can see from my quotes, I do not told YOU that but to
Ian Collins. Please try to understand how quoting works.
Jacob (and others), Usenet is NOT for private communications. Any
such should be done via email, if possible. All Usenet messages
are totally public, and addressed to the general readership. They
are delivered to the readership, barring plonking etc.

You have been told this before, but you persist in the same error.

The following is primarily for Ruuds benefit, but all are invited
to examine the referances. The C99 items (n869_txt.bz2 is bzip2
compressed) describe the standard, and all functions in the
standard library. The dinkumware reference is also an excellent
introduction the the standard library.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://c-faq.com/ (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf(C99)
<http://cbfalconer.home.att.net/download/n869_txt.bz2 (pre-C99)
<http://www.dinkumware.com/c99.aspx (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 2 '08 #36
CBFalconer wrote:
jacob navia wrote:
>Ruud wrote:
>>jacob navia wrote:

If you do not know enough C please do not use this group.
Then please be a good man and tell me what level I should have
before I can attend this group?
As you can see from my quotes, I do not told YOU that but to
Ian Collins. Please try to understand how quoting works.

Jacob (and others), Usenet is NOT for private communications.
Hey you, can't you read? My answer was public.

This is a typical facloner post.

he doesn't knopw wnything of what's going on, and goes around
by "keywords". He sees "jacobn" then, of course it must be wrong!
Any
such should be done via email, if possible. All Usenet messages
are totally public, and addressed to the general readership. They
are delivered to the readership, barring plonking etc.

You have been told this before, but you persist in the same error.
Yes falconer. You have been told this but you persist:
Read the messages and the context before spewing nonsense.
1) The OP asked a question
2) Ian collins said it wasn't possible to do that in C and that C
wasn't appropiate language for string processing.
I answered that post with a refultal and an example of how the OP
question could be answered. My answer was to Ian Collin's reply.

Look at the attributions now and follow the posts. It is not that
difficult.

Then, the OP misunderstood my quoting and thought I answered to him

Then you saw that wrong reply and without looking you take your
"professor chuck" hat and start spewing nonsense.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 2 '08 #37
In article <ge**********@registered.motzarella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrote:
>dj******@csclub.uwaterloo.ca.invalid wrote:
>[Copying a single character into a string]
>This is also a case where strncat's (generally confusing)
interpretation of its count argument turns out to be useful:
strcpy(Str1,Str2);
strncat(Str1,Str3+5,1);
(But be careful using this one in code that has to be maintained.)

... and now you need to tack on the terminating '\0'
that strncat() didn't give you.
It's strncpy that doesn't give a terminating '\0'; strncat copies at
most count characters from the source string to the end of the dest
string and then adds a '\0'. (I *did* say that it was confusing. I
had to check the man page to see which strncat was. I just checked
N1124, and it agrees with the man page (7.21.3.2).)
dave

--
Dave Vandervies dj3vande at eskimo dot com
A lot of comp.lang.c people are traditionalists. For a very long time, the
*only* date of celebration recognised all over Usenet was 1st April. In
comp.lang.c that is still more or less the case. --Richard Heathfield in CLC
Nov 2 '08 #38
dj******@csclub.uwaterloo.ca.invalid wrote:
In article <ge**********@registered.motzarella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrote:
>dj******@csclub.uwaterloo.ca.invalid wrote:
>>[Copying a single character into a string]
>>This is also a case where strncat's (generally confusing)
interpretation of its count argument turns out to be useful:
strcpy(Str1,Str2);
strncat(Str1,Str3+5,1);
(But be careful using this one in code that has to be maintained.)
... and now you need to tack on the terminating '\0'
that strncat() didn't give you.

It's strncpy that doesn't give a terminating '\0'; strncat copies at
most count characters from the source string to the end of the dest
string and then adds a '\0'. (I *did* say that it was confusing. I
had to check the man page to see which strncat was. I just checked
N1124, and it agrees with the man page (7.21.3.2).)
(Sigh.) Not my day, is it? I must have forgotten not
to take my stupid pills ...

Thanks again.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 2 '08 #39
dj******@csclub.uwaterloo.ca.invalid writes:
[...]
It's strncpy that doesn't give a terminating '\0'; strncat copies at
most count characters from the source string to the end of the dest
string and then adds a '\0'. (I *did* say that it was confusing. I
had to check the man page to see which strncat was. I just checked
N1124, and it agrees with the man page (7.21.3.2).)
N1256 is more up to date.

http://www.open-std.org/jtc1/sc22/WG...docs/n1256.pdf

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Nov 2 '08 #40
dj******@csclub.uwaterloo.ca.invalid wrote:
Eric Sosman <es*****@ieee-dot-org.invalidwrote:
.... snip ...
>
>... and now you need to tack on the terminating '\0'
that strncat() didn't give you.

It's strncpy that doesn't give a terminating '\0'; strncat copies
at most count characters from the source string to the end of the
dest string and then adds a '\0'. (I *did* say that it was
confusing. I had to check the man page to see which strncat was.
I just checked N1124, and it agrees with the man page (7.21.3.2).)
I suggest ignoring strncpy and its nuisances, and using strlcpy and
strlcat. These names are reserved, but you can change them.
Source code in standard C, and full documentation, are all
available at:

<http://cbfalconer.home.att.net/download/strlcpy.zip>

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 2 '08 #41
In article <49***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
>I suggest ignoring strncpy and its nuisances, and using strlcpy and
strlcat.
The case I was commenting on was one of the (admittedly few) cases
where strncat makes it *easier* to do The Right Thing than strlcat
would.
dave

--
Dave Vandervies dj3vande at eskimo dot com
Actually, I'm toying with approaching a mug-printing outfit to see if they can
do me an Emacs reference quart-sized mug although I fear that the text might
still be too small to read. --Peter Corlett in the scary devil monastery
Nov 3 '08 #42
Pilcrow <Pi******@gmail.comwrites:
On Sun, 02 Nov 2008 10:59:20 +1300, Ian Collins <ia******@hotmail.com>
wrote:
>>Ruud wrote:
Sorry, no. One alternative is to use a regular expression library if
you have a lot of these.

Please. Point me to a regular expression library for C. Please.
A Google search for "C regular expression library" gets about 441,000
hits; many of the first few appear to be quite relevant.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Nov 3 '08 #43
On Nov 2, 5:31*pm, CBFalconer <cb********@yahoo.comwrote:
dj******@csclub.uwaterloo.ca.invalid wrote:
Eric Sosman *<es*****@ieee-dot-org.invalidwrote:

... snip ...
... and now you need to tack on the terminating '\0'
that strncat() didn't give you.
It's strncpy that doesn't give a terminating '\0'; strncat copies
at most count characters from the source string to the end of the
dest string and then adds a '\0'. *(I *did* say that it was
confusing. *I had to check the man page to see which strncat was.
I just checked N1124, and it agrees with the man page (7.21.3.2).)

I suggest ignoring strncpy and its nuisances, and using strlcpy and
strlcat. *These names are reserved, but you can change them.
Source code in standard C, and full documentation, are all
available at:

* <http://cbfalconer.home.att.net/download/strlcpy.zip>
So you bash powerful functions like asprintf(), but advocate trivial,
ten-liner functions like strlcpy() and strlcat()?

Sebastian

Nov 3 '08 #44
On 2 Nov, 12:11, Ruud <Ruud.Baltis...@apg.nlwrote:
jacob navia wrote:
If you do not know enough C please do not use this group.

Then please be a good man and tell me what level I should have before
I can attend this group?
Jacob was talking rubbish

Chuck wrote:
<snip>
A good book, such as K&R II, would be helpful.

The book isn't the problem, see next.

Richard wrote:
Ruud, you use an odd quoting convention doesn't your
news software support the more usual conventions
(all the attributions at the top)?
Why not at least tell him about:
if(isupper(c) || isdigit(c))
and
if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", c) != NULL)

The problem is not knowing all those available functions.
yes, I remember all those functions and headers looked pretty
forbidding when I started learning C (also from pascal).
It didn't help that my implementation didn't distinguish
non-standard from standard headers.
And knowing
another language is a disavantage as well: instead of reading the book
line by line, one tends to look just at "how is this done in C".
K&R is pretty good for getting C idioms over. It really is
worth ploughing through K&R and doing the exercises. It's
not a big book (though information dense).

And even reading the book line by line isn't a guarantee for success:
there are no guarantees!
I justed searched the book "C in 21 days"
"xyz in small number days" isn't usually a promising title.
Really, give K&R a try.

I've got a book that promises to teach me to ride a horse in
a weekend...
for 'isdigit' and only found
one source file using this function. OTOH, this source file also
mentioned the function 'isspace' and this function does exactly what
one of my own made function does; detecting white space.
sprintf

Not mentioned at all "C in 21 days"
oh dear. sprintf() is *really* useful.
:( Because 'printf' was well
explained, I never used the help function of Borland C to give it a
better look. I wish I had because I just did: I learned nothing new
about 'printf' but the page also mentioned 'sprintf' and many more
other functions.

Trent wrote:
strncat(Str1, &Str3[5], 1);

Here I have no excuse, it is mentioned very clearly in the book.

--
Nick Keighley

"ALGOL 60 was a language so far ahead of its time that it
was not only an improvement on its predecessors but also
on nearly all its successors".
--C.A.R. Hoare
Nov 3 '08 #45
On 2 Nov, 22:08, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
dj3va...@csclub.uwaterloo.ca.invalid wrote:
In article <gekuc2$at...@registered.motzarella.org>,
Eric Sosman *<esos...@ieee-dot-org.invalidwrote:
dj3va...@csclub.uwaterloo.ca.invalid wrote:
>[Copying a single character into a string]
>This is also a case where strncat's (generally confusing)
interpretation of its count argument turns out to be useful:
* * strcpy(Str1,Str2);
* * strncat(Str1,Str3+5,1);
(But be careful using this one in code that has to be maintained.)
* * ... and now you need to tack on the terminating '\0'
that strncat() didn't give you.
It's strncpy that doesn't give a terminating '\0'; strncat copies at
most count characters from the source string to the end of the dest
string and then adds a '\0'. *(I *did* say that it was confusing. *I
had to check the man page to see which strncat was. *I just checked
N1124, and it agrees with the man page (7.21.3.2).)

* * *(Sigh.) *Not my day, is it? *I must have forgotten not
to take my stupid pills ...
I have a reflex, as soon as I see a string of the form strn* in a post
I start to post my standard "strncpy() may not do what you expect"
reply. I had it all composed and ready to send when I noticed he
was using strncat(). So I pressed Discard instead of Send.
But it was close :-)
--
Nick Keighley

"Resistance is futile. Read the C-faq."
-- James Hu (c.l.c.)

Nov 3 '08 #46
On 3 Nov 2008 at 7:36, s0****@gmail.com wrote:
On Nov 2, 5:31Â*pm, CBFalconer <cb********@yahoo.comwrote:
>I suggest ignoring strncpy and its nuisances, and using strlcpy and
strlcat. Â*These names are reserved, but you can change them.
Source code in standard C, and full documentation, are all
available at:

Â* <http://[spam snipped]>

So you bash powerful functions like asprintf(), but advocate trivial,
ten-liner functions like strlcpy() and strlcat()?
Yes, funny how that works, isn't it?

I often wonder what motivates CBF to post his spamming crap about
strlcpy, ggets, etc. time and time again. Maybe he makes ad revenue from
his site, or maybe it's just the ego trip of looking at his logs and
counting the number of people he manages to gull into making the mistake
of downloading his unreadable garbage.

Nov 3 '08 #47
On 3 Nov 2008 at 8:31, Nick Keighley wrote:
On 2 Nov, 12:11, Ruud <Ruud.Baltis...@apg.nlwrote:
>jacob navia wrote:
If you do not know enough C please do not use this group.

Then please be a good man and tell me what level I should have before
I can attend this group?

Jacob was talking rubbish
No, he wasn't.

He was clearly addressing Collins' arrogance in wading into a
conversation with an air of authority and spouting nonsense. Jacob was
clearly criticizing people who pretend to be C experts while in fact
talking nonsense, not newbies with genuine questions.

Nov 3 '08 #48
s0****@gmail.com wrote:
CBFalconer <cb********@yahoo.comwrote:
.... snip ...
>
>I suggest ignoring strncpy and its nuisances, and using strlcpy
and strlcat. These names are reserved, but you can change them.
Source code in standard C, and full documentation, are all
available at:

<http://cbfalconer.home.att.net/download/strlcpy.zip>

So you bash powerful functions like asprintf(), but advocate
trivial, ten-liner functions like strlcpy() and strlcat()?
Definitely. Especially functions whose complete action is easily
described. Above all when they replace variadic (and thus error
prone) functions.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 3 '08 #49
On Nov 2, 1:17*pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
dj3va...@csclub.uwaterloo.ca.invalid wrote:
* * * *strcpy(Str1, Str2);
* * * *Str1[ strlen(Str2) ] = Str3[5];
* * * *Str1[ strlen(Str2) ] = '\0';
That last line looks wrong to me; I think you want to add 1 to
strlen(Str2) before you use it as an index into Str1.

* * *Right you are. *Thanks.

Actually you need to save the result of the strlen() in the second
line, since the assignment in the second line will eliminate the NUL
in Str1.
Nov 3 '08 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris Gordon-Smith | last post by:
I am tying to call a Pascal function from C++, and vice versa. Does anyone know how to do this, or where detailed information on this topic can be found? For the C++ to Pascal call I have...
24
by: Faith Dorell | last post by:
I really donīt like C.You can write better programs in BASIC than in C, if you donīt like this language. I donīt understand how C became so popular, although much better programming languages...
14
by: digital | last post by:
hello anyone... pls explain me , how different between function and procedure for C/C++ and Pascal. Thankx......
28
by: Skybuck Flying | last post by:
Hi, I think I understand now a bit better what the difference is between a c compiler and a pascal compiler. For example: When compiling source code with a pascal compiler. The pascal...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
6
by: kkrish | last post by:
hi, I am working on an old program written in c.The program uses a function like this "unsigned long int far pascal ReadFile(char *buff,unsigned long int *size)" . Is this a PASCAL...
15
by: jacob navia | last post by:
Programming languages come and go. Still is amazing that in this survey from http://www.devsource.com/article2/0,1895,2016936,00.asp the C language comes second, right after Java. Java # What...
0
by: dhruba.bandopadhyay | last post by:
Am using Borland C++ 4.5 for the old dos.h APIs. It appears that newer versions of compilers stop support for the oldskool DOS routines. Am trying to convert/port an oldskool Pascal program that...
7
by: SMALLp | last post by:
Hy! I desperately need help! I need to make application that would accept Pascal code and check if it returns good results. My idea is (from a beginner point of view) to make application in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.