[ create a new paste ] login | about

Link: http://codepad.org/chJp5zR3    [ raw code | output | fork ]

C, pasted on Jun 7:
/*
Từ là 1 hoặc nhiều ký tự khác khoảng trắng
VD: Nam Son
=> Có 2 từ là "Nam" và "Son"
 */
#include<stdio.h>
#include<conio.h>
#include<string.h>
int DemSoTu(char *s)
{
	int length = strlen(s);
	int dem = 0;

	if(s[0] != ' ')
	{
		dem = 1;
	}
	for(int i = 0; i < length - 1; i++)
	{
		if(s[i] == ' ' && s[i + 1] != ' ')
		{
			dem++;
		}
	}
	return dem;
}
int main()
{
	char s[] = "   Nam  Son   ";

	int sotu = DemSoTu(s);
	printf("\nSo tu = %d",sotu);

	getch();
	return 0;
}


Output:
1
2
3
Line 17: error: conio.h: No such file or directory
In function 'DemSoTu':
Line 18: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: