AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

For-loop from C to Delphi

Ein Thema von WojTec · begonnen am 18. Sep 2011 · letzter Beitrag vom 19. Sep 2011
Antwort Antwort
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.658 Beiträge
 
Delphi 12 Athens
 
#1

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 07:16
I am not very familiar with C, but I think ctoi means "character to integer", which is Ord() in Delphi. There is also a function called atoi which means "ASCII to integer" (Delphi: StringToInt). Both return different results. In my opinion Ord() is the right function for your purpose.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#2

Re: For-loop from C to Delphi

  Alt 19. Sep 2011, 11:41
Thare are these functions:

Code:
int ctoi(char source)
{ /* Converts a character 0-9 to its equivalent integer value */
   if((source >= '0') && (source <= '9'))
      return (source - '0');
   return(source - 'A' + 10);
}

char itoc(int source)
{ /* Converts an integer value to its hexadecimal character */
   if ((source >= 0) && (source <= 9)) {
      return ('0' + source); }
   else {
      return ('A' + (source - 10)); }
}
StrToInt working. But I'm still confused, what difference between ctoi() and atoi() if char in C is byte? You told C.atoi() = Delphi.StrToInt(), the same doing ctoi()?

Code:
s = "C++";
i = atoi(s[0]);
i = ctoi(s[0]);
i = s[0];
What values are assigned to i in these cases?

Delphi-Quellcode:
s = 'C++';
i = Ord(s[0]);
i = StrToInt(s[0]);
i = Ord(s[0]);
?
  Mit Zitat antworten Zitat
Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.492 Beiträge
 
Delphi 7 Enterprise
 
#3

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 11:52
Delphi-Quellcode:
StrCopy(s, 'C++');
i := Ord(s[0]); -> 67
i := StrToInt(s[0]); -> Invalid since 'Cis no number
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.688 Beiträge
 
Delphi 2007 Enterprise
 
#4

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:02
More importantly: When working with Delphi Strings, keep in mind that their index starts with 1! If you have an array of char, the first index is zero though.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.658 Beiträge
 
Delphi 12 Athens
 
#5

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:03
As shown in #4
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.688 Beiträge
 
Delphi 2007 Enterprise
 
#6

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:24
Easy to forget, since Union seemed to use a zero base on Strings, which can lead to quite some confusion - I know that first hand, since I regularly forget it myself. But you're right of course
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.492 Beiträge
 
Delphi 7 Enterprise
 
#7

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:30
Yes this was for PChar (see StrCopy). But the principle was to show the StrToInt() and Ord() function's results.
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:47 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz