473,791 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
54 3186
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.c om>
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.c omwrites:
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_Keit h) 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.c om>
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_Keit h) 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**********@r egistered.motza rella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrot e:

[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,Str 2);
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,Str 2);
strncat(Str1,St r3+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.i nvalid wrote:
In article <ge**********@r egistered.motza rella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrot e:

[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,Str 2);
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,Str 2);
strncat(Str1,St r3+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:com p.lang.c:Introd uction>

--
[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**********@r egistered.motza rella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrot e:
>dj******@csclu b.uwaterloo.ca. invalid wrote:
>[Copying a single character into a string]
>This is also a case where strncat's (generally confusing)
interpretati on of its count argument turns out to be useful:
strcpy(Str1,Str 2);
strncat(Str1,St r3+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.i nvalid wrote:
In article <ge**********@r egistered.motza rella.org>,
Eric Sosman <es*****@ieee-dot-org.invalidwrot e:
>dj******@csclub .uwaterloo.ca.i nvalid wrote:
>>[Copying a single character into a string]
>>This is also a case where strncat's (generally confusing)
interpretatio n of its count argument turns out to be useful:
strcpy(Str1,Str 2);
strncat(Str1,St r3+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.i nvalid 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_Keit h) 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

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

Similar topics

4
4393
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 tried declaring the Pascal function as:- extern "C" void PASCALTESTFUNC1(); within my C++ code. However, the linker is giving me an unresolved
24
3483
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 existed in the 70s or 80s or 90s. Pascal is much better.
14
23438
by: digital | last post by:
hello anyone... pls explain me , how different between function and procedure for C/C++ and Pascal. Thankx......
28
2282
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 compiler will simply stop when it is missing an implementation for a procedure or whatever.
17
4379
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 problem writing VB Double values to the file so as the Pascal program can read them as Pascal Real values. I've managed to find the algorithm to read the Pascal Real format and convert it to a VB Double, but I cannot figure out the opposite...
6
6914
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 function CALL from C?Do I need to have Pascal installed in my system.This has been written in Turbo C 2.0 under
15
1744
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 it is: An object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. # Job availabilities: 14,408
0
1584
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 uses registers/ interrupts into C/C++. 1. What are the inline($FA); & inline($FB); Pascal functions? What is the C/C++ equivalent? inline($CD / $1C); inline($9C);
7
5978
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 python that would send code (text) to pascal compiler (Free pascal compiler that can be used from command prompt in windows) and it would return result and then application would show that result.
0
9517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.