Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

새싹교실/2020/새싹부터나무까지/박소은/실습/20.10.09: Difference between revisions

From ZeroWiki
No edit summary
No edit summary
Line 30: Line 30:
  void strcat(char s1[], char s2[])
  void strcat(char s1[], char s2[])
  {
  {
  for (int i = strlen(s1); i < strlen(s1) + strlen(s2); i++)
  for (int i = strlen(s1), j = 0; i <= strlen(s1) + strlen(s2); i++, j++)
  {
  {
  s1[i] = s2[i];
  s1[i] = s2[j];
  }
  }
  }
  }

Revision as of 14:26, 11 November 2020

1

//strcpy

char* strcpy(char s1[], char s2[])
{
	int i = 0;
	while (*(s2 + i))
	{
		s1[i] = s2[i];
		i++;
	}
	s1[i] = s2[i];
	return s1;
}

2

//strlen

int strlen(char* p)
{
	int length = 0, i = 0;
	while (*(p + i)) {
		length++;
		i++;
	}
	return length;
}

3

//strcat

void strcat(char s1[], char s2[])
{
	for (int i = strlen(s1), j = 0; i <= strlen(s1) + strlen(s2); i++, j++)
	{
		s1[i] = s2[j];
	}
}

4

//strcmp

int strcmp(char s1[], char s2[])
{
	int i = 0;
	while (s1[i] != '\0' || s2[i] != '\0')
	{
		if (s1[i] > s2[i])
			return 1;
		else if (s1[i] < s2[i])
			return -1;
		i++;
	}
	return 0;
}