Summary of Array Search Methods
#Programming#C
I. Introduction
The following explanation is based on a function that converts zone codes to Unicode in a Chinese character set.
DWORD Unicode2GBQuWei(WORD wUnicode){ DWORD dwQuNum; DWORD dwWeiNum; DWORD i,dwResult = 0; for(i = 0; i < MAXUNICODENUM; i++) // Simplest and most straightforward search implementation { if(wUnicode == Unicode[i]) { dwResult = 0; if(GBQuWei[i] != DNULL) { dwQuNum = (DWORD)GBQuWei[i]; // Following four lines apply conversion rules dwWeiNum = (DWORD)GBQuWei[i]; dwQuNum = (dwQuNum & 0xff00) >> 8; dwWeiNum = dwWeiNum & 0x00ff; if(dwQuNum < 0x58) { dwDispAddQuWeiChinese(dwQuNum,dwWeiNum); } else { // The required Chinese character is not present in the dot matrix font library dwDispAddQuWeiChinese(4, 1); } } else { // The required Chinese character is not present in the dot matrix font library dwDispAddQuWeiChinese(4, 2); } return dwResult; } else { dwResult = 1; } } if(dwResult == 1) { dwDispAddQuWeiChinese(4, 3); } return dwResult;}
DWORD GBQuWei2Unicode(DWORD dwQuNum, DWORD dwWeiNum){ DWORD i,dwResult = 0; WORD wQuWeiNum; wQuWeiNum = (WORD)(dwQuNum << 8) + (WORD)dwWeiNum; for(i = 0; i < MAXUNICODENUM; i++) { if(wQuWeiNum == GBQuWei[i]) { dwResult = (DWORD)Unicode[i]; return dwResult; } else { dwResult = 0; } } return dwResult;}
II. Debugging
- Segmentation fault
What could be causing this? Is it due to overflow or insufficient memory? But why do other programs run successfully?
III. MIT Practices
- Steps for learning new content:
-
Resolve terminology first.
-
Start with applications. As Linus said, learn to use it first. Once you've used it, curiosity arises, and following that interest becomes a motivating and enjoyable learning path (interest is the best teacher).
- Observe, identify patterns, and cultivate patience.
For example, Newton's observations of light.
- In complex problems, unfamiliarity with C syntax can become a significant issue. To reduce error probability and lower problem complexity, mastering C syntax, common programming patterns, and typical issues is a wise choice.