c²Ù×÷·×ª×Ö·û´®
#include<stdio.h>
#include<malloc.h>
#include<string.h>
/*
* ·×ª
*/
char *mystrrev(char *arr)
{
if (!arr)
{
return NULL;
}
char *temp = arr;
char t;
int leng = strlen(arr) + 1;
int l = (int)(leng / 2);
int i = 0;
while (l--)
{
t = arr[i];
arr[i] = arr[leng - 2];
arr[leng - 2] = t;
i++;
leng--;
}
return temp;
}
/*
*½ØÈ¡µ¥¸ö´Ê»ã
*/
char *myrev(char *string)
{
if (!string)
{
return NULL;
}
char *temp1 = (char *)malloc(strlen(string) + 1);
char *temp2 = (char *)malloc(strlen(string) + 1);
char *temp3 = NULL;
*temp2 = '\0';
int i = 0;
for (int j=strlen(string); j>=0; --j)
{
temp1[i] = *string;
if (temp1[i] == ' ' || *(string) == '\0')
{
if (!temp3)
{
free(temp3);
temp3 = NULL;
}
temp3 = (char *)malloc(i);
temp1[i] = '\0';
i = 0;
strcpy(temp3, temp1);
strcat(temp2, mystrrev(temp3));
strcat(temp2, " ");
i = -1;
}
i++;
string++;
}
if (!temp1)
{
free(temp1);
temp1 = NULL;
}
if (!temp3)
{
free(temp3);
temp3 = NULL;
}
return temp2;
}
int main(int argc, char *argv[])
{
char *src = "Today is a good day";
char *s = "abcd_*__abcd";
char *temp = myrev(src);
char *temp1 = myrev(s);
printf("%s\n", temp);
printf("%s\n", temp1);
return 0;
}
½á¹û£º
yadoT si a doog yad
dcba__*_dcba
Ïà¹ØÎĵµ£º
ÕâÊÇCµÄÔ³ÌÐò
#include <stdio.h>
#include <regex.h>
int main(int argc, char** argv)
{
regex_t reg;
regmatch_t pm[10];
char *pattern;
char buf[50];
const size_t nmatch = 10;
pattern = argv[1];
int result = regcomp(®, pattern, REG_EXTENDED);
while( fgets ......
תCºÍ»ã±à»ìºÏ±à³Ì
.dataÊdzõʼ»¯µÄÊý¾Ý¿é¡£ÕâЩÊý¾Ý°üÀ¨±àÒëʱ±»³õʼ»¯µÄglobleºÍstatic±äÁ¿£¬Ò²°üÀ¨×Ö·û´®¡£
Á¬½ÓÆ÷½«OBJs¼°LIBsÎļþµÄ.data½áºÏ³ÉÒ»¸ö´óµÄ.data¡£local±äÁ¿ÒÔ·ÅÔÚÒ»¸öÏßÐԵĶÑÕ»ÖУ¬
²»Õ¼.dataºÍ.bssµÄ¿Õ¼ä¡£ºÍ.textÒ»Ñù£¬Êý¾Ý¿éÊÇÒÔÃ÷ÎĵÄÐÎʽ´æ·ÅÔÚÎļþÖеġ£ÎÞ·¨·ÀÖ¹¶ÔÆäÎïÀíµÄÐ޸ġ£
.bssÇøÊÇ´æ· ......
CºÍC++»¥Ïàµ÷Óú¯Êýʱ£¬Ê¹ÓÃextern "C"¡£
ÔÒò£º
C²»Ö§³Öº¯ÊýÖØÔØ£¬¶øC++Ö§³Öº¯ÊýÖØÔØ¡£º¯Êý±»C++±àÒëºó»áÃû×ÖÓëCÓïÑÔ²»Í¬¡£¼ÙÉèijº¯ÊýÔÐÍΪfoo(ing x, int y)£¬±»C++±àÒëºóÃû×ÖΪ_foo_int_int£¬¶øC±àÒëÆ÷±àÒëºóÃû×ÖΪ_foo¡£ ......