structure affectation and comparison (with string field)

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

structure affectation and comparison (with string field)

Post by eddy »

How to compare some structure-type variables:
- this structure comparison works only if you replace unlimited strings by fixed strings.

Code: Select all

#MaxCharacters=$FF
Structure country
   name.s{#MaxCharacters} ; fixed string ( 256 characters )
   townCount.i
   towns.s{#MaxCharacters}[10] ;array of fixed strings ( 256 characters per string )
   *history
EndStructure
Macro CompareCountry(this, other)
   CompareMemory(@this, @other, SizeOf(country))
EndMacro

thisCountry.country
thisCountry\name="Funky Land"
thisCountry\townCount=2
thisCountry\towns[0]="Small-City"
thisCountry\towns[1]="Barney Ville"
thisCountry\history=AllocateMemory(1024)

;structure affectation
otherCountry.country =thisCountry

If CompareCountry(thisCountry, otherCountry)
   Debug "same country"
EndIf
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool