ɾ³ýc/c++Ô´³ÌÐòÖеÄ×¢ÊÍ
ÌâÄ¿£º±àдһ¸ö³ÌÐò£¬ÓÃÓÚ´¦Àíc/c++Ô´³ÌÐò£¬½«Ô´³ÌÐòÖеÄ×¢ÊͲ¿·ÖÈ¥µô
ÊäÈ룺c/c++ÎļþÃû
Êä³ö£º´¦ÀíºóµÄ³ÌÐòÔ´Îļþ
³ÌÐòα´úÂëÈçÏ£º
c1,c2:char
tag:int
a:¶ÁÈëÒ»¸ö×Ö·û´æÈëc1
if tag==0 //¶ÁÈë×Ö·û²»ÊÇ×¢ÊÍ
if c1=='/' //¿ÉÄÜÊÇ×¢Êͱê¼Ç
¶ÁÈëÒ»¸ö×Ö·û´æÈëc2
if c2=='*' //Ϊ/**/×¢Ê͵ĿªÍ·
tag = 2
else if c2=='/' //Ϊ//×¢Ê͵ĿªÍ·
tag = 1
else //²»ÊÇ×¢Êͱê¼Ç
½«c1, c2±£´æ
else //¶ÁÈëµÄ×Ö·ûΪ´úÂë
±£´æc1
else if tag==1 //¶ÁÈëµÄÊÇ//×¢ÊÍ
if c1=='\n' //ΪעÊͽáÊø±ê¼Ç
tag=0
else //¶ÁÈëµÄÊÇ/**/×¢ÊÍtag==2
if c1=='*' //¿ÉÄÜΪעÊͽáÊø±ê¼Ç
¶ÁÈëÒ»¸ö×Ö·û¸³¸øc2
if c2=='/' //ÊÇ/**/×¢Êͽáβ
tag=0
else //×¢ÊÍûÓнáÊø
nothing
goto a
³ÌÐòÇåµ¥ÈçÏ£º
//¶ÔÔ´Îļþ½øÐÐɨÃ裬ɾ³ýÆäÖеÄ×¢ÊÍ
#include <stdio.h>
void scan(char *filename)
{
int tag=0;//0:¶ÁÈ¡µÄ×Ö·ûΪ´úÂ룻1:¶ÁÈ¡µÄ×Ö·ûΪ//×¢ÊÍ£»2:¶ÁÈ¡µÄ×Ö·ûΪ/**/×¢ÊÍ
char temp1, temp2;
FILE *in, *out;
in = fopen(filename,"r");
if(in==NULL)
{
printf("cannot open the input file!");
}
out = fopen("out.c", "w");
if(out==NULL)
{
printf("cannot open the output file!");
}
temp1 = fgetc(in);
while(temp1!=EOF)
{
printf("%c", temp1);
if(0==tag)
{
if('/'==temp1)
{
temp2 = fgetc(in);
if('*'==temp2)
{
tag = 2;
}
else if('/'==temp2)
{
tag = 1;
}
else
{
fputc(temp1, out);
fputc(temp2, out);
}
}
else
{
fputc(temp1, out);
}
}
else if(1==tag)
{
if('\n'==temp1)
{
tag = 0;
}
}
else
{
if('*'==temp1)
{
temp2 =
Ïà¹ØÎĵµ£º
ÓÃÁËÈýÖÖ·½·¨...
#if 0
void StringTokenize(const std::string& strSrc, const std::string& strDelimit, std::vector<std::string>& vecSub)
{
if (strSrc.empty() || strDelimit.empty())
{
throw "tokenize: empty string\n";
......
// & Óë,½«Ö¸¶¨Î»ÖÃÉèÖÃΪ0 | »ò,½«Ö¸¶¨Î»ÖÃÉèÖÃΪ1
//×¢: Ö»Õë¶Ô´¿×ÖĸµÄÇé¿ö
#include <stdio.h>
#include <string>
int main()
{
char str[6] = "xxing";
std::string str1 = "INGXX";
for(int i = 0; i < 5; i++)
{
str[i] &= 0xdf; ......
ÎÊÌâÃèÊö£ºÐ´Ò»¸öº¯Êý£¬½ÓÊÜÒ»¸öÕûÊý£¨¼Ù¶¨ÓÃint±íʾ£©£¬Êä³ö¸ÃÕûÊýµÄ×Ö·û´®ÐÎʽ¡£²ÉÓÃÈçϺ¯ÊýÔÐÍ£º
void itoa ( int val, buf* );
ÕâÀï¼Ù¶¨buf×ã¹»´óÒÔÈÝÄÉÈκÎintÀàÐÍÊýÖµµÄ×Ö·û´®¡£
Õâ¸öÎÊÌ⣬³õ¿´ºÃÏñûÓÐʲôÄѶȡ£Èç¹ûÊÇ0£¬¾ÍÖ±½ÓÊä³ö'0'£»Èç¹ûÊÇÕýÊý£¬¾Íͨ¹ýÈ¡Ä£(%)ºÍÇóÉÌ(/)ÔËËã¿ÉÒÔÖðλȡµÃ¸ÃÕûÊýµÄÊý×Ö£¬²¢° ......