C/C++·ç¸ñ×Ö·û´®
Ò»£º×Ö·û´®ÀàÐÍ·ÖÀࣺ
1. C·ç¸ñ×Ö·û´®£ºÆðÔ´ÓÚC£¬²¢ÔÚC++Öеõ½Ö§³Ö¡£
a. ´æ´¢·½Ê½£º±»´æ´¢ÔÚÒ»¸ö×Ö·ûÊý×éÖУ¬Í¨¹ýÒ»¸öchar*ÀàÐ͵ÄÖ¸ÕëÀ´²Ù×ÝËü¡£
b. ÌṩµÄ¿âº¯Êý£º°üº¬Í·Îļþ£º#include<cstring>
a) int strlen( const char* );//·µ»Ø×Ö·û´®µÄ³¤¶È
b) int strcmp( const char*, const char* );//±È½ÏÁ½¸ö×Ö·û´®ÊÇ·ñÏàµÈ
c) char* strcpy( char*, const char* );//°ÑµÚ¶þ¸ö×Ö·û´®¿½±´µ½µÚÒ»¸ö×Ö·û´®ÖÐ
#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;
void main()
{
char* arraya = "hello world!";
int c;
c = strlen(arraya);
cout<<c<<endl;
char arrayb[80];
char * test = NULL;
test = strcpy (arrayb, arraya);
cout<<"test is: "<<test<<endl;
cout<<arrayb<<endl;
int d;
d = strcmp(arrayb,arraya);
cout<<endl<<"d->"<<d<<endl;
}Õâ¶Î´úÂë°üº¬ÁËÒÔÉÏÈý¸ö¿âº¯ÊýµÄʹÓá£
¶þ£ºc++·ç¸ñµÄstring
1. ÎÒÃÇʹÓÃstring£¬ËüµÄ¿âº¯ÊýÓкܶ࣬µ±ÎÒÃÇÐèÒª»ñµÃij¸ö×Ö·û´®µÄ³¤¶ÈµÄʱºò£¬¿ÉÒÔµ÷ÓÃsize()º¯Êý£º
ÕâÀïÎÒÃǶ¨ÒåÒ»¸östring£ºstring sa = “hello world!”;
1£© ÎÒÃǵ÷ÓÃsize()º¯Êý£ºsa.size();ËüµÄÖµ¾ÍÊÇ12£»
2£© ÎÒÃÇÐèÒªÅжÏÒ»¸ö×Ö·û´®ÊÇ·ñΪ¿ÕµÄʱºò£¬ÎÒÃÇ¿ÉÒÔµ÷ÓÃempty()º¯ÊýÀ´Åжϣºsa.empty();ÈôÕâ¸ö×Ö·û´®Îª¿Õ£¬ÄÇôËü½«·µ»Ø1£¬Èô²»Îª¿Õ£¬Ôò·µ»Ø0¡£
3£© ÎÒÃÇ»áÓõ½¿½±´×Ö·û´®µÄÇé¿ö£¬ÔÚÎÒÃdzõʼ»¯Ò»¸ö×Ö·û´®µÄʱºò£¬ÎÒÃÇ¿ÉÒÔ³õʼ»¯³ÉÒ»¸ö×Ö·û´®µÄ¿½±´£ºstring sc(sa);ÔÚÕâ¶Î´úÂëºó£¬scµÄÄÚÈݺÍsa¾ÍÍêÈ«ÏàͬÁË¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒ»¸öÅжÏÓï¾äÀ´ÅжÏÕâÁ½¸ö×Ö·û´®ÊÇ·ñÏàµÈ£ºif( sc == sa)…
&nb
Ïà¹ØÎĵµ£º
char a[10];
Ôõô¸øÕâ¸öÊý×鸳ֵÄØ£¿
1¡¢¶¨ÒåµÄʱºòÖ±½ÓÓÃ×Ö·û´®¸³Öµ
char a[10]="hello";
×¢Ò⣺²»ÄÜÏȶ¨ÒåÔÙ¸øËü¸³Öµ£¬Èçchar a[10]; a[10]="hello";ÕâÑùÊÇ´íÎóµÄ£¡
2¡¢¶ÔÊý×éÖÐ×Ö·ûÖð¸ö¸³Öµ
char a[10]={'h','e','l','l','o'};
3¡¢ÀûÓÃstrcpy
char a[10]; strcpy(a, "hello");
Ò×´íÇé¿ö£º
1¡¢char a[1 ......
1£®½ø³ÌºÍÏ̵߳IJî±ð¡£
Ïß³ÌÊÇÖ¸½ø³ÌÄÚµÄÒ»¸öÖ´Ðе¥Ôª,Ò²Êǽø³ÌÄڵĿɵ÷¶ÈʵÌå.
Óë½ø³ÌµÄÇø±ð:
(1)µ÷¶È£ºÏß³Ì×÷Ϊµ÷¶ÈºÍ·ÖÅäµÄ»ù±¾µ¥Î»£¬½ø³Ì×÷ΪӵÓÐ×ÊÔ´µÄ»ù±¾µ¥Î»
(2)²¢·¢ÐÔ£º²»½ö½ø³ÌÖ®¼ä¿ÉÒÔ²¢·¢Ö´ÐУ¬Í¬Ò»¸ö½ø³ÌµÄ¶à¸öÏß³ÌÖ®¼äÒ²¿É²¢·¢Ö´ÐÐ
(3)ÓµÓÐ×ÊÔ´£º½ø³ÌÊÇÓµÓÐ×ÊÔ´µÄ¶ÀÁ¢µ¥Î»£¬Ï̲߳»ÓµÓÐϵͳ×ÊÔ´£¬µ«¿ÉÒ ......
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <conio.h>
typedef struct {
short int pitch;
short int duration;
} NOTE;
NOTE notes[] = {{14, 500}, {16, 500}, {12, 500 ......
¡¾checkpass.c¡¿
#include <stdio.h>
#include <string.h>
int checkpass(void){
int x;
char a[9];
x = 0;
fprintf(stderr,"a at %p and\nx at %p\n", (void *)a, (void *)&x);
printf("Enter a short word: ");
&nbs ......
......