Two string operation functions.

Source: Internet
Author: User

/*! Brief copies the last part of the string.

Compile the strmcpy (S, T, m) function, and copy all the characters starting from the M character to the string S. N
Difficulty coefficient: simple
Param [in] source string. Read-Only
Param [in] DEST destination string
Param [in] nstart starts from nstart
Bug
-# Strlen (source) <nstart is not taken into account. (error)
-# Dest [] insufficient space is not taken into account. (error)
-# The source does not end with '/0'. (error)
.

Pre source is zero Ending & strlen (source)> nstart & sizeof (DEST)> sizeof (source)
Post DEST is zero Ending & strcmp (DEST, source + nstart) = 0
*/
Void leftsubstr (char * Source, char * DEST, int nstart)
{
Char * P = source + nstart;
Char * q = DEST;
While (* q ++ = * P ++ );
}

 

// 4. write a function, input a string containing numbers and non-numeric characters, and take its continuous numbers as an integer, store them in array a in sequence, and count the number of integers.

// If the database is not used:
Int isdigit (int c)
{
Return! (C <'0' | C> '9 ');
}

Int atoi (char * Str)
{
Char * P = STR;
Int sum = * P-'0 ';
While (isdigit (* ++ p ))
{
Sum = sum * 10 + (* P-'0 ');
}

Return sum;
}

Int finddigital (char * STR, int Buf [], int nlen)
{
Char * P = STR;
Int I;
For (I = 0; I <nlen & * P; I ++)
{
While (* P &&! Isdigit (* ++ p ));
Buf [I] = atoi (P );
While (isdigit (* ++ p ));
}
Return I;
}

# Include <stdio. h>

Int main ()
{
Int A [10];
Int Len = finddigital ("-11,2", A, 10 );
Printf ("% d, % d, % d", Len, a [0], a [1]);
Return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.