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 54 3172
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
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];
Unfortunatel y 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
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
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.
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
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
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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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.
|
by: digital |
last post by:
hello anyone...
pls explain me , how different between function and procedure for C/C++ and Pascal.
Thankx......
|
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.
|
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...
| |
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
|
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
|
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);
|
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.
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |