Use of STRCHR () strncpy () in C language and cutting strings based on a character

Source: Internet
Author: User
#define _crt_secure_no_warnings
#include <stdlib.h>
#include <string.h>
#include <
the use of stdio.h>//STRCHR () strncpy () and the cutting string
int splitstring (char* p1, char C, char buffer[10][30], int * Based on a character Count) {
	char* p = null, *ptmp = NULL;
	int tempcount = 0;
	p = p1;
	Ptmp = p1;
	while (*p!= ' I ') {
		p = STRCHR (P, c);//Check the position p ( 
		p!=null)
		{
			if (p-ptmp>0)//To calculate the position of the pointer that matches the condition
			{
				strncpy (buffer[tempcount],ptmp,p-ptmp);
				BUFFER[TEMPCOUNT][P-PTMP] = ' tempcount++ ';//Become a C-style string
				;
				ptmp = p = p + 1;
			}}
		else {break
			;
		}

	}
	*count = tempcount;//specifically has several split strings return
	0;
}


void Main () {
	int ret = 0, i = 0;
	char* p1 = "ABCDEF,ACCCD,BDDDDFDF,FFFF,KJKJLKJKL";
	Char SPLITC = ', ';
	int ncout;
	Char myarray[10][30];
	ret = Splitstring (P1, SPLITC, myarray, &ncout);
	for (i = 0; i < ncout i++)
	{
		printf ("%s\n", Myarray[i]);

	System ("pause");
}

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.