[ create a new paste ] login | about

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

C, pasted on Nov 24:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>

int STRLEN(char s[])
{
	int dem = 0;
	while (s[dem] != '\0')
	{
		dem++;
	}
	return dem;
}

// SUBSTR(s, x, y) // Cắt chuỗi con trong đoạn [x, y] của chuỗi s

char* SUBSTR(char s[], int x, int y)
{
	char ketqua[100];
	int length = STRLEN(s);
	int idx = 0;
	for(int i = x; i <= y; i++)
	{
		ketqua[idx++] = s[i];
	}
	ketqua[idx] = '\0'; // Kết thúc chuỗi
	return ketqua;
}
int main()
{
	char s[] = "Vuong Tri Tai";
	char sub[100];
	strcpy(sub, SUBSTR(s, 10, 12));

	printf("\nsub = %s", sub);

	getch();
	return 0;
}


Output:
1
2
3
4
Line 17: error: conio.h: No such file or directory
In function 'SUBSTR':
Line 23: error: 'for' loop initial declaration used outside C99 mode
Line 28: warning: function returns address of local variable


Create a new paste based on this one


Comments: