(. 9.17).
. 9.17.
. ( , ). .
/++, .
strcmp()
. :
strcmp(buf1, buf2)
strcmp ( );
buf1, buf2 ;
() .
string.h.
1. (buf1 buf2).
2. buf1 buf2 .
3. buf1 buf2 \0 .
4. , .
5. ( ), .
6. , .
7. (, , , , ).
8. ( ).
buf str:
#include <string.h> /* */
char str[25], buf[10]; /* */
int result; /* */
EditStr->GetText(str, 12); /* str EditStr*/
EditBuf->GetText(buf, 10); /* buf EditBuf*/
result = strcmp(str, buf); /* buf str*/
str buf 25 10 . str buf EditStr EditBuf . str buf result.
strcpy()
. , . :
|
|
strcpy(buf1, buf2)
strcpy ;
buf1 ;
buf2 ;
() .
string.h.
1. buf2 \0.
2. buf2 buf1. \0 ( ).
3. - ( ).
4. .
5. () .
buf str:
#include <string.h> /* */
char str[25] = , buf[10]; /* */
EditBuf->GetText(buf, 10); /* buf EditBuf*/
strcpy(str, buf); /* str buf*/
str buf 25 10 str . buf EditBuf. strcpy(str, buf); str, buf.
, .
. 9.7.
9.7
n | i | j | i | j | ||
strpr | n | i | j | str[i] | str[j] |
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<string.h>
#define N 25
main()
{
int i,j,n; /* */
char str[N][30], strpr[30], /* */
buf[40]; /**/
clrscr();
for(i=0; i < N; i++)
{
CharToOem(" ",buf);
printf("\n %s[%d] ",buf,i+1); /* */
gets(str[i]); /* */
if(str[i][0] == '\0') /* */
break;
else
n = i + 1;
}
CharToOem(" \n \n", buf);
printf("%s",buf);
for(i=0;i<n;i++)
printf(" %s \n ",str[i]);
for (i=0; i< n-1; i++)/* . */
for(j=i+1; j<n; j++) /* . */
if(strcmp(str[i],str[j]) >0)
{
strcpy(strpr, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j],strpr);
}
CharToOem(" \n \n",buf);
printf("%s",buf);
for(i=0;i<n;i++)
printf(" %s \n ",str[i]);
getch();
}
..
..
..
..
..
.
9.13.
.
|
(EditStr). - (ListBoxSortStr).
|
|
, . .
.
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#define N 25
void TVrDlgClient::BNClickedOk()
{
// INSERT>> Your code here.
int i,j,n; /* */
char str[N][30],strpr[30]; /* */
ListBoxSortStr->ClearList();
for(i=0; i < N; i++)
{
EditStr->GetLine(str[i],30,i); /* */
if(str[i][0] == '\0') /* */
break;
else
n = i + 1;
}
for (i=0; i< n-1; i++)/* . */
for(j=i+1; j<n; j++) /* . */
if(strcmp(str[i],str[j]) >0)
{
strcpy(strpr, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j],strpr);
}
for (i=0; i< n; i++)/* . */
ListBoxSortStr->AddString(str[i]); /* */
}
..
..
..
..
..
.
9.14.
, .
() , .
() , .
.
:
;
.
() , ();
() , .
( ).
(), , . . , .
( ). , , , , .
( ) .
/++ .
() ().
, .
.
.
ASCII ANSI 000 255. :
;
;
(A Z);
(a z);
( );
( ).
( ) , .
|
|
: .
.
. .
1. ?
2. , ?
3. ?
4. ?
5. ?
6. ?
7. ?
8. ?
9. ?
10. ?
11. ?
12. ?
13. ?
14. ()?
15. ?
16. ?
17. ?