[ create a new paste ] login | about

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

C, pasted on Nov 24:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int STRLEN(char s[])
{
	int count = 0;
	while (s[count] != '\0')
	{
		count++;
	}
	return count;
}
// strcpy (String Copy) dùng để sao chép toàn bộ ký tự của chuỗi này qua chuỗi khác.
void STRCPY(char s1[], char s2[])  // copy chuoi s2 vao chuoi s1
{
	int i = 0;
	while(s2[i] != '\0')
	{
		s1[i] = s2[i];
		i++;
	}
	s1[i] = '\0';
}

void STRCPY_2(char s1[], char s2[])
{
	int length = STRLEN(s2);
	for (int i = 0; i < length; i++)
	{
		s1[i] = s2[i];
	}
	s1[length] = '\0';
}
int main()
{
	char str1[100], str2[100];

    printf("Nhap chuoi: ");
	//scanf("%s",str2);
    gets(str2);  // phải dùng gets
    STRCPY_2(str1,str2);
    printf("Chuoi sau khi nhap: %s",str1);
 
    
	getch();
	return 0;
}


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


Create a new paste based on this one


Comments: