帕斯卡 - C(2) [英] Pascal - C (2)
问题描述
在我的程序从Pascal转换为C的过程中,到目前为止,我更多或者没有能够找到大多数Pascal函数的C等价物。
只有四个给了我一些真正的麻烦。我解决了它们,但它可能是我
忽略了一些东西。
1)在Pascal中你可以在函数内声明函数。 AFAIK这个
是不可能的C.或者我错了吗?
2)在Pascal中存在in功能。例如:
if(c in [''A''''''F'',''0''..''9'']){c is十六进制}
这可以翻译成:
if(((c> =''A'')&& (c< =''Z''))
||((c> =''0'')&&(c< ='''9'')) ).... // c是十六进制的
我只是想知道是否有更简单的解决方案。
3)在Pascal我可以添加行:
行1 =''文件大小:''+ sSize +''字节。'';
我的解决方案:
strcpy(Line1," File size:");
strcat(Line1,sSize);
strcat(第1行, 字节。;
再次,我只是想知道是否有更简单的解决方案。
4)在Pascal中,我可以 ;新增]只是另一个字符串中的一个字符:
Str1 = Str2 + Str3 [5];
不幸的是strcat(Str1,Str3 [5]) ;不行,我收到一个错误
消息。我的解决方案:
Str4 [0] = Str3 [5];
Str4 [1] = 0;
strcpy( Str1,Str2};
strcat(Str1,Str4};
它有效但在这种情况下我肯定对解决方案不满意。
还有更好的方法吗?
非常感谢您的任何评论!
-
___
/ __ | __
/ / | _ / Groetjes,Ruud Baltissen
\ \__ | _ \
\ ___ | http://Ruud.C64.org >
Ruud写道:
Hallo allemaal,
在我的程序从Pascal转换为C的过程中,到目前为止,我更多或者没有能够找到大多数Pascal函数的C等价物。
只有四个给了我真的遇到了麻烦。我解决了他们但是我可能会忽略一些东西。
1)在Pascal中你是在函数内声明函数。 AFAIK这个
是不可能的C.或者我错了吗?
不,C没有嵌套函数,尽管有些编译器支持
它们作为扩展。
2)在Pascal中存在in功能。例如:
if(c in [''A''''''F'',''0''..''9'']){c is十六进制}
这可以翻译成:
if(((c> =''A'')&& (c< =''Z''))
||((c> =''0'')&&(c< ='''9'')) ).... // c是十六进制的
我只是想知道是否有更简单的解决方案。
对不起不,不。一种替代方法是使用正则表达式库,如果你有很多这些。
3)在Pascal我可以添加 ;行:
行1 =''文件大小:''+ sSize +''字节。'';
我的解决方案:
strcpy(Line1," File size:");
strcat(Line1,sSize);
strcat(第1行, bytes。;
再次,我只是想知道是否有更简单的解决方案。
不在C中。
4)在Pascal我可以添加只是另一个字符串中的一个字符:
Str1 = Str2 + Str3 [5];
不幸的是strcat(Str1,Str3 [5]) ;不行,我收到一个错误
消息。我的解决方案:
Str4 [0] = Str3 [5];
Str4 [1] = 0;
strcpy( Str1,Str2};
strcat(Str1,Str4};
它有效但在这种情况下我肯定对解决方案不满意。
还有更好的方法吗?
不要使用C. C没有字符串对象,char数组和
库函数可以操作。
如果你正在进行大量的字符串操作,C可能不是你最好的选择。像Perl这样的脚本语言专为字符串处理而设计
并且可能是更好的选择。
-
Ian Collins
Ian Collins写道:
Ruud写道:
> Hallo allemaal,
3)在Pascal中,我可以添加行:
Line1 ='''文件大小:''+ sSize +''字节。'';
我的解决方案:
strcpy(Line1," File size:");
strcat(Line1,sSize);
strcat(Line1,"字节。);
再次,我只是想知道是否有更简单的解决方案。
不在C.
这是无稽之谈
sprintf(第1行,文件大小:%s字节,sSize);
>
并且您可以保存自己将大小转换为字符串
sprintf(第1行,文件大小:%d字节,大小);
< blockquote class =post_quotes>
>
> 4)在Pascal我可以添加只是另一个字符串中的一个字符:
Str1 = Str2 + Str3 [5];
不幸的是strcat(Str1,Str3 [5]);不行,我收到错误消息。我的解决方案:
Str4 [0] = Str3 [5];
Str4 [1] = 0;
strcpy(Str1,Str2};
strcat(Str1 ,Str4};
它有效但在这种情况下我肯定对解决方案不满意。
有更好的方法吗?
不要使用C. C没有字符串对象,char数组和
库函数来操作。
如果你不太了解C,请不要使用这个组。
以上可以用
sprintf( str1,"%s%c",str2,Str3 [5]);
如果你正在进行大量的字符串操作,C可能会不是你最好的
选择。像Perl这样的脚本语言专为字符串处理而设计
并且可能是更好的选择。
C有字符串问题但可以使用。其他语言有其他
(更大)问题
-
jacob navia
jacob at jacob point remcomp point fr
logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32
Ruud写道:
Hallo allemaal,
在我的程序从Pascal转换为C期间,我更多或者<到目前为止,
能够找到大多数Pascal函数的C等价物。
只有四个给了我一些真正的麻烦。我解决了它们,但它可能是我
忽略了一些东西。
1)在Pascal中你可以在函数内声明函数。 AFAIK这个
是不可能的C.或者我错了吗?
2)在Pascal中存在in功能。例如:
if(c in [''A''''''F'',''0''..''9'']){c is十六进制}
这可以翻译成:
if(((c> =''A'')&& (c< =''Z''))
||((c> =''0'')&&(c< ='''9'')) ).... // c是十六进制的
我只是想知道是否有更简单的解决方案。
那个一个很简单
3)在Pascal我可以添加行:
行1 =''文件大小:''+ sSize +''字节。'';
我的解决方案:
strcpy(Line1," File size:");
strcat(Line1,sSize);
strcat(第1行, bytes。;
再次,我只是想知道是否有更简单的解决方案。
是:
sprintf(第1行,文件大小:%s字节,sSize);
>
并且您可以保存自己将大小转换为字符串
sprintf(第1行,文件大小:%d字节,大小);
< blockquote class =post_quotes>
>
4)在Pascal我可以添加只是另一个字符串中的一个字符:
Str1 = Str2 + Str3 [5];
不幸的是strcat(Str1,Str3 [5]) ;不行,我收到一个错误
消息。我的解决方案:
Str4 [0] = Str3 [5];
Str4 [1] = 0;
strcpy( Str1,Str2};
strcat(Str1,Str4};
它有效但在这种情况下我肯定对解决方案不满意。
还有更好的方法吗?
是的。
以上可以用
sprintf(str1,"%s%c",Str2,Str3 [5]);
非常感谢任何评论!
-
___
/ __ | __
/ / | _ / 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
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
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];
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
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
这篇关于帕斯卡 - C(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!