我现在需要从一个文件中读取字符串,然后分析这个字符串,得到我想要得数据。不知道在标准C中都有哪些用来作为字符串分析的函数。多谢啦!!!
29 个解决方案
#1
用C++的流
#2
string.h里面有好多呀
以str开头的,还有atoi,atol之类的
复杂就自己进行指针操作么
以str开头的,还有atoi,atol之类的
复杂就自己进行指针操作么
#3
用正规表达式
#4
atof,atoi,atol
#5
不知你所说的"分析"是什么意思?
字符串处理的函数很多了.
example:
strcat, wcscat, _mbscat
Append a string.
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscat( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcat <string.h> ANSI, Win 95, Win NT
wcscat <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscat <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string (strDestination). No return value is reserved to indicate an error.
Parameters
strDestination
Null-terminated destination string
strSource
Null-terminated source string
Remarks
The strcat function appends strSource to strDestination and terminates the resulting string with a null character. The initial character of strSource overwrites the terminating null character of strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcat is undefined if the source and destination strings overlap.
wcscat and _mbscat are wide-character and multibyte-character versions of strcat. The arguments and return value of wcscat are wide-character strings; those of _mbscat are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscat strcat _mbscat wcscat
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
strchr, wcschr, _mbschr
Find a character in a string.
char *strchr( const char *string, int c );
wchar_t *wcschr( const wchar_t *string, wint_t c );
unsigned char *_mbschr( const unsigned char *string, unsigned int c );
Routine Required Header Compatibility
strchr <string.h> ANSI, Win 95, Win NT
wcschr <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbschr <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to the first occurrence of c in string, or NULL if c is not found.
Parameters
string
Null-terminated source string
c
Character to be located
Remarks
The strchr function finds the first occurrence of c in string, or it returns NULL if c is not found. The null-terminating character is included in the search.
wcschr and _mbschr are wide-character and multibyte-character versions of strchr. The arguments and return value of wcschr are wide-character strings; those of _mbschr are multibyte-character strings. _mbschr recognizes multibyte-character sequences according to the multibyte code page currently in use. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcschr strchr _mbschr wcschr
Example
/* STRCHR.C: This program illustrates searching for a character
* with strchr (search forward) or strrchr (search backward).
*/
#include <string.h>
#include <stdio.h>
int ch = 'r';
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] = " 1 2 3 4 5";
char fmt2[] = "12345678901234567890123456789012345678901234567890";
void main( void )
{
char *pdest;
int result;
printf( "String to be searched: \n\t\t%s\n", string );
printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
printf( "Search char:\t%c\n", ch );
/* Search forward. */
pdest = strchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tfirst %c found at position %d\n\n",
ch, result );
else
printf( "Result:\t%c not found\n" );
/* Search backward. */
pdest = strrchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tlast %c found at position %d\n\n", ch, result );
else
printf( "Result:\t%c not found\n" );
}
Output
String to be searched:
The quick brown dog jumps over the lazy fox
1 2 3 4 5
12345678901234567890123456789012345678901234567890
Search char: r
Result: first r found at position 12
Result: last r found at position 30
strcmp, wcscmp, _mbscmp
Compare strings.
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int _mbscmp(const unsigned char *string1, const unsigned char *string2 );
Routine Required Header Compatibility
strcmp <string.h> ANSI, Win 95, Win NT
wcscmp <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscmp <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
The return value for each of these functions indicates the lexicographic relation of string1 to string2.
Value Relationship of string1 to string2
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
On an error, _mbscmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.
Parameters
string1, string2
Null-terminated strings to compare
Remarks
The strcmp function compares string1 and string2 lexicographically and returns a value indicating their relationship. wcscmp and _mbscmp are wide-character and multibyte-character versions of strcmp. The arguments and return value of wcscmp are wide-character strings; those of _mbscmp are multibyte-character strings. _mbscmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. (For more information, see Code Pages.) These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscmp strcmp _mbscmp wcscmp
The strcmp functions differ from the strcoll functions in that strcmp comparisons are not affected by locale, whereas the manner of strcoll comparisons is determined by the LC_COLLATE category of the current locale. For more information on the LC_COLLATE category, see setlocale.
In the “C” locale, the order of characters in the character set (ASCII character set) is the same as the lexicographic character order. However, in other locales, the order of characters in the character set may differ from the lexicographic order. For example, in certain European locales, the character 'a' (value 0x61) precedes the character 'ä' (value 0xE4) in the character set, but the character 'ä' precedes the character 'a' lexicographically.
In locales for which the character set and the lexicographic character order differ, use strcoll rather than strcmp for lexicographic comparison of strings according to the LC_COLLATE category setting of the current locale. Thus, to perform a lexicographic comparison of the locale in the above example, use strcoll rather than strcmp. Alternatively, you can use strxfrm on the original strings, then use strcmp on the resulting strings.
_stricmp, _wcsicmp, and _mbsicmp compare strings by first converting them to their lowercase forms.Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if the comparison is uppercase.
Example
/* STRCMP.C */
#include <string.h>
#include <stdio.h>
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}
Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
strcpy, wcscpy, _mbscpy
Copy a string.
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcpy <string.h> ANSI, Win 95, Win NT
wcscpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscpy <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string. No return value is reserved to indicate an error.
Parameters
strDestination
Destination string
strSource
Null-terminated source string
Remarks
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcpy is undefined if the source and destination strings overlap.
wcscpy and _mbscpy are wide-character and multibyte-character versions of strcpy. The arguments and return value of wcscpy are wide-character strings; those of _mbscpy are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscpy strcpy _mbscpy wcscpy
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
.......................
.......................
.......................
参考MSDN.
字符串处理的函数很多了.
example:
strcat, wcscat, _mbscat
Append a string.
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscat( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcat <string.h> ANSI, Win 95, Win NT
wcscat <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscat <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string (strDestination). No return value is reserved to indicate an error.
Parameters
strDestination
Null-terminated destination string
strSource
Null-terminated source string
Remarks
The strcat function appends strSource to strDestination and terminates the resulting string with a null character. The initial character of strSource overwrites the terminating null character of strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcat is undefined if the source and destination strings overlap.
wcscat and _mbscat are wide-character and multibyte-character versions of strcat. The arguments and return value of wcscat are wide-character strings; those of _mbscat are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscat strcat _mbscat wcscat
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
strchr, wcschr, _mbschr
Find a character in a string.
char *strchr( const char *string, int c );
wchar_t *wcschr( const wchar_t *string, wint_t c );
unsigned char *_mbschr( const unsigned char *string, unsigned int c );
Routine Required Header Compatibility
strchr <string.h> ANSI, Win 95, Win NT
wcschr <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbschr <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to the first occurrence of c in string, or NULL if c is not found.
Parameters
string
Null-terminated source string
c
Character to be located
Remarks
The strchr function finds the first occurrence of c in string, or it returns NULL if c is not found. The null-terminating character is included in the search.
wcschr and _mbschr are wide-character and multibyte-character versions of strchr. The arguments and return value of wcschr are wide-character strings; those of _mbschr are multibyte-character strings. _mbschr recognizes multibyte-character sequences according to the multibyte code page currently in use. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcschr strchr _mbschr wcschr
Example
/* STRCHR.C: This program illustrates searching for a character
* with strchr (search forward) or strrchr (search backward).
*/
#include <string.h>
#include <stdio.h>
int ch = 'r';
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] = " 1 2 3 4 5";
char fmt2[] = "12345678901234567890123456789012345678901234567890";
void main( void )
{
char *pdest;
int result;
printf( "String to be searched: \n\t\t%s\n", string );
printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
printf( "Search char:\t%c\n", ch );
/* Search forward. */
pdest = strchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tfirst %c found at position %d\n\n",
ch, result );
else
printf( "Result:\t%c not found\n" );
/* Search backward. */
pdest = strrchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tlast %c found at position %d\n\n", ch, result );
else
printf( "Result:\t%c not found\n" );
}
Output
String to be searched:
The quick brown dog jumps over the lazy fox
1 2 3 4 5
12345678901234567890123456789012345678901234567890
Search char: r
Result: first r found at position 12
Result: last r found at position 30
strcmp, wcscmp, _mbscmp
Compare strings.
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int _mbscmp(const unsigned char *string1, const unsigned char *string2 );
Routine Required Header Compatibility
strcmp <string.h> ANSI, Win 95, Win NT
wcscmp <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscmp <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
The return value for each of these functions indicates the lexicographic relation of string1 to string2.
Value Relationship of string1 to string2
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
On an error, _mbscmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.
Parameters
string1, string2
Null-terminated strings to compare
Remarks
The strcmp function compares string1 and string2 lexicographically and returns a value indicating their relationship. wcscmp and _mbscmp are wide-character and multibyte-character versions of strcmp. The arguments and return value of wcscmp are wide-character strings; those of _mbscmp are multibyte-character strings. _mbscmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. (For more information, see Code Pages.) These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscmp strcmp _mbscmp wcscmp
The strcmp functions differ from the strcoll functions in that strcmp comparisons are not affected by locale, whereas the manner of strcoll comparisons is determined by the LC_COLLATE category of the current locale. For more information on the LC_COLLATE category, see setlocale.
In the “C” locale, the order of characters in the character set (ASCII character set) is the same as the lexicographic character order. However, in other locales, the order of characters in the character set may differ from the lexicographic order. For example, in certain European locales, the character 'a' (value 0x61) precedes the character 'ä' (value 0xE4) in the character set, but the character 'ä' precedes the character 'a' lexicographically.
In locales for which the character set and the lexicographic character order differ, use strcoll rather than strcmp for lexicographic comparison of strings according to the LC_COLLATE category setting of the current locale. Thus, to perform a lexicographic comparison of the locale in the above example, use strcoll rather than strcmp. Alternatively, you can use strxfrm on the original strings, then use strcmp on the resulting strings.
_stricmp, _wcsicmp, and _mbsicmp compare strings by first converting them to their lowercase forms.Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if the comparison is uppercase.
Example
/* STRCMP.C */
#include <string.h>
#include <stdio.h>
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}
Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
strcpy, wcscpy, _mbscpy
Copy a string.
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcpy <string.h> ANSI, Win 95, Win NT
wcscpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscpy <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string. No return value is reserved to indicate an error.
Parameters
strDestination
Destination string
strSource
Null-terminated source string
Remarks
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcpy is undefined if the source and destination strings overlap.
wcscpy and _mbscpy are wide-character and multibyte-character versions of strcpy. The arguments and return value of wcscpy are wide-character strings; those of _mbscpy are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscpy strcpy _mbscpy wcscpy
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
.......................
.......................
.......................
参考MSDN.
#6
不知你所说的"分析"是什么意思?
字符串处理的函数很多了.
strcat, wcscat, _mbscat
strchr, wcschr, _mbschr
.....
参考MSDN.
字符串处理的函数很多了.
strcat, wcscat, _mbscat
strchr, wcschr, _mbschr
.....
参考MSDN.
#7
我说的字符串分析是指从一个字符串中取得我感兴趣的数据,而不是对字符串进行处理。比如有一个字符串,中间有空格或tab键,后边是我想要的数据,我曾经见过这样的函数,但现在具体的忘了,如果哪为知道,敬请告知,如有详细资料或例程更好,定重谢!!!
#8
网上的高手看过来,看过来,这里的问题很精彩,请你们快点回答。
(白)这样我才好给分哪
(白)这样我才好给分哪
#9
sscanf
#10
好像不是sscanf,sscanf只是从一个字符串中读取格式化的数据,而我需要的函数需要用在如下的情况下:有一个字符串,它的前一部分是使一些说明性的字符串,中间有一个空格或tab键,后边就是所要求的数据。我需要首先跳过这些说明性的字符,当然这可以自己通过编程实现,但我记得有这个函数,不用它我觉得心里难受,希望各位大虾能够体谅小弟的苦衷。
#11
你可能要用到
strstr
strspn
strncpy
strstr
strspn
strncpy
#12
你们可能还不太理解我所说的意思,我不是要找到一个字符串,或进行字符串拷贝。请再看看我所说的。大家请继续吧,我这里也查一查资料。。。
#13
希望下面的代码对你有帮助(耐心看)
void getProperty(char *src, char *property)
{
char *rtnstr;
char *tmpstr;
char result[strlen(src) + 1];
char cmpstr[strlen(src) + 1];
int j=0;
int i=0;
int k=0;
int x=0;
int t=0;
int n=0;
int c=0;
int strlength;
result[0]='\0';
memset(result,0,sizeof(result));
memset(cmpstr,0,sizeof(cmpstr));
t = strlen(src);
for(n = 0;n <= t;n++)
{
cmpstr[n]=tolower(src[n]);
if (src[n] == '\n' && src[n+1] == '\n') break;
}
strlength = strlen(property);
k = strlength;
if (strstr(cmpstr, property))
{
tmpstr = strstr(cmpstr, property);
c = strlen(cmpstr) - strlen(tmpstr);
}
else
{
strcpy(property,"");
return;
}
if (tmpstr)
{
rtnstr = (char *)malloc(strlen(src) + 1);
while(src[k+c] != '\0')
{
if(src[k+c] == '\n' && (src[k+c+1] != '\t' && src[k+c+1] != ' '))
break;
result[k-strlength] = src[k+c];
k++;
}
result[k-strlength] = '\0';
}
for (x = 0; x < ( strlen(result) ); x++)
{
if (rtnstr[x] == '\r' && rtnstr[x+1] == '\n')
break;
else
rtnstr[x] = result[x];
}
rtnstr[x] = '\0';
strcpy(property,rtnstr);
free(rtnstr);
return;
}
void getProperty(char *src, char *property)
{
char *rtnstr;
char *tmpstr;
char result[strlen(src) + 1];
char cmpstr[strlen(src) + 1];
int j=0;
int i=0;
int k=0;
int x=0;
int t=0;
int n=0;
int c=0;
int strlength;
result[0]='\0';
memset(result,0,sizeof(result));
memset(cmpstr,0,sizeof(cmpstr));
t = strlen(src);
for(n = 0;n <= t;n++)
{
cmpstr[n]=tolower(src[n]);
if (src[n] == '\n' && src[n+1] == '\n') break;
}
strlength = strlen(property);
k = strlength;
if (strstr(cmpstr, property))
{
tmpstr = strstr(cmpstr, property);
c = strlen(cmpstr) - strlen(tmpstr);
}
else
{
strcpy(property,"");
return;
}
if (tmpstr)
{
rtnstr = (char *)malloc(strlen(src) + 1);
while(src[k+c] != '\0')
{
if(src[k+c] == '\n' && (src[k+c+1] != '\t' && src[k+c+1] != ' '))
break;
result[k-strlength] = src[k+c];
k++;
}
result[k-strlength] = '\0';
}
for (x = 0; x < ( strlen(result) ); x++)
{
if (rtnstr[x] == '\r' && rtnstr[x+1] == '\n')
break;
else
rtnstr[x] = result[x];
}
rtnstr[x] = '\0';
strcpy(property,rtnstr);
free(rtnstr);
return;
}
#14
不会是词法和语法分析吧,那就是lex和yacc;啊
#15
多谢jacky的鼎力帮助,我一定会给你相应的报酬的(虽然你不一定在意),但你的代码实在太神奇了,我捉摸了半天,没有解决我的问题,所以还起你仔细看一下我上面所说的,多谢,拜托!!!
#16
to:jackeyjia(Jackey)
你的编码风格,我值得的是if的括号写法,我也喜欢这样的。
但是有的人不喜欢,曾经还大大的讨论过那。
你的编码风格,我值得的是if的括号写法,我也喜欢这样的。
但是有的人不喜欢,曾经还大大的讨论过那。
#17
void an(char * str)
{
while(*str!=32&&*str!=9)
{str++;
}
str++;
}
是这意思么?
{
while(*str!=32&&*str!=9)
{str++;
}
str++;
}
是这意思么?
#18
to:(getmoon)
我也喜欢用这种编码风格,但问题它的代码没有解决我的问题。
to:(maquanjun)
不是这样的,你再看看我neuliuhy(solar)上面所说的。
我也喜欢用这种编码风格,但问题它的代码没有解决我的问题。
to:(maquanjun)
不是这样的,你再看看我neuliuhy(solar)上面所说的。
#19
你应该举一个例子了,这么多人都看不懂你想要什么
#20
有人知道他问什么吗?
#21
哈哈
#22
支持支持
#23
值得注意
#24
比如说,这里有一个字符串:
IP address: 192.168.39.108
现在我想从这个字符串中取出这IP地址,用一个函数直接跳IP地址的开始处,从中取出IP地址,就这么简单!!!但小的没想出来是哪一个函数,请各位高手指点。
IP address: 192.168.39.108
现在我想从这个字符串中取出这IP地址,用一个函数直接跳IP地址的开始处,从中取出IP地址,就这么简单!!!但小的没想出来是哪一个函数,请各位高手指点。
#25
问题仍然没有解决!!!
各位高手,快来帮忙!!!!
各位高手,快来帮忙!!!!
#26
对字符串分析,就是词法分析。
使用lex,几乎不要写任何C代码,windows和linux下都有lex。
使用lex,几乎不要写任何C代码,windows和linux下都有lex。
#27
等待中...
#28
c中好像并无此种函数,只能自己写一个这样的函数.一行读出,找到特定值取出所需字符串.这种类似的事情我也作过.
#29
有这个函数,我曾经见过。只不过我现在忘了,我原先在那里看过也忘了,看来我只好去自己编写程序实现了
#1
用C++的流
#2
string.h里面有好多呀
以str开头的,还有atoi,atol之类的
复杂就自己进行指针操作么
以str开头的,还有atoi,atol之类的
复杂就自己进行指针操作么
#3
用正规表达式
#4
atof,atoi,atol
#5
不知你所说的"分析"是什么意思?
字符串处理的函数很多了.
example:
strcat, wcscat, _mbscat
Append a string.
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscat( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcat <string.h> ANSI, Win 95, Win NT
wcscat <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscat <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string (strDestination). No return value is reserved to indicate an error.
Parameters
strDestination
Null-terminated destination string
strSource
Null-terminated source string
Remarks
The strcat function appends strSource to strDestination and terminates the resulting string with a null character. The initial character of strSource overwrites the terminating null character of strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcat is undefined if the source and destination strings overlap.
wcscat and _mbscat are wide-character and multibyte-character versions of strcat. The arguments and return value of wcscat are wide-character strings; those of _mbscat are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscat strcat _mbscat wcscat
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
strchr, wcschr, _mbschr
Find a character in a string.
char *strchr( const char *string, int c );
wchar_t *wcschr( const wchar_t *string, wint_t c );
unsigned char *_mbschr( const unsigned char *string, unsigned int c );
Routine Required Header Compatibility
strchr <string.h> ANSI, Win 95, Win NT
wcschr <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbschr <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to the first occurrence of c in string, or NULL if c is not found.
Parameters
string
Null-terminated source string
c
Character to be located
Remarks
The strchr function finds the first occurrence of c in string, or it returns NULL if c is not found. The null-terminating character is included in the search.
wcschr and _mbschr are wide-character and multibyte-character versions of strchr. The arguments and return value of wcschr are wide-character strings; those of _mbschr are multibyte-character strings. _mbschr recognizes multibyte-character sequences according to the multibyte code page currently in use. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcschr strchr _mbschr wcschr
Example
/* STRCHR.C: This program illustrates searching for a character
* with strchr (search forward) or strrchr (search backward).
*/
#include <string.h>
#include <stdio.h>
int ch = 'r';
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] = " 1 2 3 4 5";
char fmt2[] = "12345678901234567890123456789012345678901234567890";
void main( void )
{
char *pdest;
int result;
printf( "String to be searched: \n\t\t%s\n", string );
printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
printf( "Search char:\t%c\n", ch );
/* Search forward. */
pdest = strchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tfirst %c found at position %d\n\n",
ch, result );
else
printf( "Result:\t%c not found\n" );
/* Search backward. */
pdest = strrchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tlast %c found at position %d\n\n", ch, result );
else
printf( "Result:\t%c not found\n" );
}
Output
String to be searched:
The quick brown dog jumps over the lazy fox
1 2 3 4 5
12345678901234567890123456789012345678901234567890
Search char: r
Result: first r found at position 12
Result: last r found at position 30
strcmp, wcscmp, _mbscmp
Compare strings.
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int _mbscmp(const unsigned char *string1, const unsigned char *string2 );
Routine Required Header Compatibility
strcmp <string.h> ANSI, Win 95, Win NT
wcscmp <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscmp <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
The return value for each of these functions indicates the lexicographic relation of string1 to string2.
Value Relationship of string1 to string2
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
On an error, _mbscmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.
Parameters
string1, string2
Null-terminated strings to compare
Remarks
The strcmp function compares string1 and string2 lexicographically and returns a value indicating their relationship. wcscmp and _mbscmp are wide-character and multibyte-character versions of strcmp. The arguments and return value of wcscmp are wide-character strings; those of _mbscmp are multibyte-character strings. _mbscmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. (For more information, see Code Pages.) These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscmp strcmp _mbscmp wcscmp
The strcmp functions differ from the strcoll functions in that strcmp comparisons are not affected by locale, whereas the manner of strcoll comparisons is determined by the LC_COLLATE category of the current locale. For more information on the LC_COLLATE category, see setlocale.
In the “C” locale, the order of characters in the character set (ASCII character set) is the same as the lexicographic character order. However, in other locales, the order of characters in the character set may differ from the lexicographic order. For example, in certain European locales, the character 'a' (value 0x61) precedes the character 'ä' (value 0xE4) in the character set, but the character 'ä' precedes the character 'a' lexicographically.
In locales for which the character set and the lexicographic character order differ, use strcoll rather than strcmp for lexicographic comparison of strings according to the LC_COLLATE category setting of the current locale. Thus, to perform a lexicographic comparison of the locale in the above example, use strcoll rather than strcmp. Alternatively, you can use strxfrm on the original strings, then use strcmp on the resulting strings.
_stricmp, _wcsicmp, and _mbsicmp compare strings by first converting them to their lowercase forms.Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if the comparison is uppercase.
Example
/* STRCMP.C */
#include <string.h>
#include <stdio.h>
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}
Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
strcpy, wcscpy, _mbscpy
Copy a string.
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcpy <string.h> ANSI, Win 95, Win NT
wcscpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscpy <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string. No return value is reserved to indicate an error.
Parameters
strDestination
Destination string
strSource
Null-terminated source string
Remarks
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcpy is undefined if the source and destination strings overlap.
wcscpy and _mbscpy are wide-character and multibyte-character versions of strcpy. The arguments and return value of wcscpy are wide-character strings; those of _mbscpy are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscpy strcpy _mbscpy wcscpy
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
.......................
.......................
.......................
参考MSDN.
字符串处理的函数很多了.
example:
strcat, wcscat, _mbscat
Append a string.
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscat( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcat <string.h> ANSI, Win 95, Win NT
wcscat <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscat <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string (strDestination). No return value is reserved to indicate an error.
Parameters
strDestination
Null-terminated destination string
strSource
Null-terminated source string
Remarks
The strcat function appends strSource to strDestination and terminates the resulting string with a null character. The initial character of strSource overwrites the terminating null character of strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcat is undefined if the source and destination strings overlap.
wcscat and _mbscat are wide-character and multibyte-character versions of strcat. The arguments and return value of wcscat are wide-character strings; those of _mbscat are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscat strcat _mbscat wcscat
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
strchr, wcschr, _mbschr
Find a character in a string.
char *strchr( const char *string, int c );
wchar_t *wcschr( const wchar_t *string, wint_t c );
unsigned char *_mbschr( const unsigned char *string, unsigned int c );
Routine Required Header Compatibility
strchr <string.h> ANSI, Win 95, Win NT
wcschr <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbschr <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to the first occurrence of c in string, or NULL if c is not found.
Parameters
string
Null-terminated source string
c
Character to be located
Remarks
The strchr function finds the first occurrence of c in string, or it returns NULL if c is not found. The null-terminating character is included in the search.
wcschr and _mbschr are wide-character and multibyte-character versions of strchr. The arguments and return value of wcschr are wide-character strings; those of _mbschr are multibyte-character strings. _mbschr recognizes multibyte-character sequences according to the multibyte code page currently in use. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcschr strchr _mbschr wcschr
Example
/* STRCHR.C: This program illustrates searching for a character
* with strchr (search forward) or strrchr (search backward).
*/
#include <string.h>
#include <stdio.h>
int ch = 'r';
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] = " 1 2 3 4 5";
char fmt2[] = "12345678901234567890123456789012345678901234567890";
void main( void )
{
char *pdest;
int result;
printf( "String to be searched: \n\t\t%s\n", string );
printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
printf( "Search char:\t%c\n", ch );
/* Search forward. */
pdest = strchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tfirst %c found at position %d\n\n",
ch, result );
else
printf( "Result:\t%c not found\n" );
/* Search backward. */
pdest = strrchr( string, ch );
result = pdest - string + 1;
if( pdest != NULL )
printf( "Result:\tlast %c found at position %d\n\n", ch, result );
else
printf( "Result:\t%c not found\n" );
}
Output
String to be searched:
The quick brown dog jumps over the lazy fox
1 2 3 4 5
12345678901234567890123456789012345678901234567890
Search char: r
Result: first r found at position 12
Result: last r found at position 30
strcmp, wcscmp, _mbscmp
Compare strings.
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int _mbscmp(const unsigned char *string1, const unsigned char *string2 );
Routine Required Header Compatibility
strcmp <string.h> ANSI, Win 95, Win NT
wcscmp <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscmp <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
The return value for each of these functions indicates the lexicographic relation of string1 to string2.
Value Relationship of string1 to string2
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
On an error, _mbscmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.
Parameters
string1, string2
Null-terminated strings to compare
Remarks
The strcmp function compares string1 and string2 lexicographically and returns a value indicating their relationship. wcscmp and _mbscmp are wide-character and multibyte-character versions of strcmp. The arguments and return value of wcscmp are wide-character strings; those of _mbscmp are multibyte-character strings. _mbscmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. (For more information, see Code Pages.) These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscmp strcmp _mbscmp wcscmp
The strcmp functions differ from the strcoll functions in that strcmp comparisons are not affected by locale, whereas the manner of strcoll comparisons is determined by the LC_COLLATE category of the current locale. For more information on the LC_COLLATE category, see setlocale.
In the “C” locale, the order of characters in the character set (ASCII character set) is the same as the lexicographic character order. However, in other locales, the order of characters in the character set may differ from the lexicographic order. For example, in certain European locales, the character 'a' (value 0x61) precedes the character 'ä' (value 0xE4) in the character set, but the character 'ä' precedes the character 'a' lexicographically.
In locales for which the character set and the lexicographic character order differ, use strcoll rather than strcmp for lexicographic comparison of strings according to the LC_COLLATE category setting of the current locale. Thus, to perform a lexicographic comparison of the locale in the above example, use strcoll rather than strcmp. Alternatively, you can use strxfrm on the original strings, then use strcmp on the resulting strings.
_stricmp, _wcsicmp, and _mbsicmp compare strings by first converting them to their lowercase forms.Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if the comparison is uppercase.
Example
/* STRCMP.C */
#include <string.h>
#include <stdio.h>
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}
Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
strcpy, wcscpy, _mbscpy
Copy a string.
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char *strSource );
Routine Required Header Compatibility
strcpy <string.h> ANSI, Win 95, Win NT
wcscpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscpy <mbstring.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the destination string. No return value is reserved to indicate an error.
Parameters
strDestination
Destination string
strSource
Null-terminated source string
Remarks
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcpy is undefined if the source and destination strings overlap.
wcscpy and _mbscpy are wide-character and multibyte-character versions of strcpy. The arguments and return value of wcscpy are wide-character strings; those of _mbscpy are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscpy strcpy _mbscpy wcscpy
Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
Output
String = Hello world from strcpy and strcat!
.......................
.......................
.......................
参考MSDN.
#6
不知你所说的"分析"是什么意思?
字符串处理的函数很多了.
strcat, wcscat, _mbscat
strchr, wcschr, _mbschr
.....
参考MSDN.
字符串处理的函数很多了.
strcat, wcscat, _mbscat
strchr, wcschr, _mbschr
.....
参考MSDN.
#7
我说的字符串分析是指从一个字符串中取得我感兴趣的数据,而不是对字符串进行处理。比如有一个字符串,中间有空格或tab键,后边是我想要的数据,我曾经见过这样的函数,但现在具体的忘了,如果哪为知道,敬请告知,如有详细资料或例程更好,定重谢!!!
#8
网上的高手看过来,看过来,这里的问题很精彩,请你们快点回答。
(白)这样我才好给分哪
(白)这样我才好给分哪
#9
sscanf
#10
好像不是sscanf,sscanf只是从一个字符串中读取格式化的数据,而我需要的函数需要用在如下的情况下:有一个字符串,它的前一部分是使一些说明性的字符串,中间有一个空格或tab键,后边就是所要求的数据。我需要首先跳过这些说明性的字符,当然这可以自己通过编程实现,但我记得有这个函数,不用它我觉得心里难受,希望各位大虾能够体谅小弟的苦衷。
#11
你可能要用到
strstr
strspn
strncpy
strstr
strspn
strncpy
#12
你们可能还不太理解我所说的意思,我不是要找到一个字符串,或进行字符串拷贝。请再看看我所说的。大家请继续吧,我这里也查一查资料。。。
#13
希望下面的代码对你有帮助(耐心看)
void getProperty(char *src, char *property)
{
char *rtnstr;
char *tmpstr;
char result[strlen(src) + 1];
char cmpstr[strlen(src) + 1];
int j=0;
int i=0;
int k=0;
int x=0;
int t=0;
int n=0;
int c=0;
int strlength;
result[0]='\0';
memset(result,0,sizeof(result));
memset(cmpstr,0,sizeof(cmpstr));
t = strlen(src);
for(n = 0;n <= t;n++)
{
cmpstr[n]=tolower(src[n]);
if (src[n] == '\n' && src[n+1] == '\n') break;
}
strlength = strlen(property);
k = strlength;
if (strstr(cmpstr, property))
{
tmpstr = strstr(cmpstr, property);
c = strlen(cmpstr) - strlen(tmpstr);
}
else
{
strcpy(property,"");
return;
}
if (tmpstr)
{
rtnstr = (char *)malloc(strlen(src) + 1);
while(src[k+c] != '\0')
{
if(src[k+c] == '\n' && (src[k+c+1] != '\t' && src[k+c+1] != ' '))
break;
result[k-strlength] = src[k+c];
k++;
}
result[k-strlength] = '\0';
}
for (x = 0; x < ( strlen(result) ); x++)
{
if (rtnstr[x] == '\r' && rtnstr[x+1] == '\n')
break;
else
rtnstr[x] = result[x];
}
rtnstr[x] = '\0';
strcpy(property,rtnstr);
free(rtnstr);
return;
}
void getProperty(char *src, char *property)
{
char *rtnstr;
char *tmpstr;
char result[strlen(src) + 1];
char cmpstr[strlen(src) + 1];
int j=0;
int i=0;
int k=0;
int x=0;
int t=0;
int n=0;
int c=0;
int strlength;
result[0]='\0';
memset(result,0,sizeof(result));
memset(cmpstr,0,sizeof(cmpstr));
t = strlen(src);
for(n = 0;n <= t;n++)
{
cmpstr[n]=tolower(src[n]);
if (src[n] == '\n' && src[n+1] == '\n') break;
}
strlength = strlen(property);
k = strlength;
if (strstr(cmpstr, property))
{
tmpstr = strstr(cmpstr, property);
c = strlen(cmpstr) - strlen(tmpstr);
}
else
{
strcpy(property,"");
return;
}
if (tmpstr)
{
rtnstr = (char *)malloc(strlen(src) + 1);
while(src[k+c] != '\0')
{
if(src[k+c] == '\n' && (src[k+c+1] != '\t' && src[k+c+1] != ' '))
break;
result[k-strlength] = src[k+c];
k++;
}
result[k-strlength] = '\0';
}
for (x = 0; x < ( strlen(result) ); x++)
{
if (rtnstr[x] == '\r' && rtnstr[x+1] == '\n')
break;
else
rtnstr[x] = result[x];
}
rtnstr[x] = '\0';
strcpy(property,rtnstr);
free(rtnstr);
return;
}
#14
不会是词法和语法分析吧,那就是lex和yacc;啊
#15
多谢jacky的鼎力帮助,我一定会给你相应的报酬的(虽然你不一定在意),但你的代码实在太神奇了,我捉摸了半天,没有解决我的问题,所以还起你仔细看一下我上面所说的,多谢,拜托!!!
#16
to:jackeyjia(Jackey)
你的编码风格,我值得的是if的括号写法,我也喜欢这样的。
但是有的人不喜欢,曾经还大大的讨论过那。
你的编码风格,我值得的是if的括号写法,我也喜欢这样的。
但是有的人不喜欢,曾经还大大的讨论过那。
#17
void an(char * str)
{
while(*str!=32&&*str!=9)
{str++;
}
str++;
}
是这意思么?
{
while(*str!=32&&*str!=9)
{str++;
}
str++;
}
是这意思么?
#18
to:(getmoon)
我也喜欢用这种编码风格,但问题它的代码没有解决我的问题。
to:(maquanjun)
不是这样的,你再看看我neuliuhy(solar)上面所说的。
我也喜欢用这种编码风格,但问题它的代码没有解决我的问题。
to:(maquanjun)
不是这样的,你再看看我neuliuhy(solar)上面所说的。
#19
你应该举一个例子了,这么多人都看不懂你想要什么
#20
有人知道他问什么吗?
#21
哈哈
#22
支持支持
#23
值得注意
#24
比如说,这里有一个字符串:
IP address: 192.168.39.108
现在我想从这个字符串中取出这IP地址,用一个函数直接跳IP地址的开始处,从中取出IP地址,就这么简单!!!但小的没想出来是哪一个函数,请各位高手指点。
IP address: 192.168.39.108
现在我想从这个字符串中取出这IP地址,用一个函数直接跳IP地址的开始处,从中取出IP地址,就这么简单!!!但小的没想出来是哪一个函数,请各位高手指点。
#25
问题仍然没有解决!!!
各位高手,快来帮忙!!!!
各位高手,快来帮忙!!!!
#26
对字符串分析,就是词法分析。
使用lex,几乎不要写任何C代码,windows和linux下都有lex。
使用lex,几乎不要写任何C代码,windows和linux下都有lex。
#27
等待中...
#28
c中好像并无此种函数,只能自己写一个这样的函数.一行读出,找到特定值取出所需字符串.这种类似的事情我也作过.
#29
有这个函数,我曾经见过。只不过我现在忘了,我原先在那里看过也忘了,看来我只好去自己编写程序实现了