ex250609 - Hwanghyewon06/c- GitHub Wiki
๊ณผ์ ๋ฌธ์์ด ๊ฒ์ํ๋ฉด ์ญ์ ํ๋ ๊ฒ
๋ค์์ฃผ๊น์ง ์์ผ๋ก ์์ฑ ๊ฐ๋ณ ๊ณผ์
#include <stdio.h>
int main()
{
int arr[10] = { 10, 20 ,30, 40, 50 };
int count = 5;
int delIndex = 1;
for(int i = delIndex; i < count- 1; ++i)
arr[i] = arr[i+1];
--count;
for (int i = 0; i < count; ++i)
printf("[%d]: %d\n", i, arr[i]);
}
//#include <stdio.h>
//int main()
//{
// int arr[10] = { 10, 20 ,30, 40, 50 };
// int count = 5;
//
// int delIndex = 1;
// arr[delIndex] = arr[count-1];
// --count;
//
//
// for (int i = 0; i < count; ++i)
// printf("[%d]: %d\n", i, arr[i]);
//
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <conio.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//void PrintStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// printf("string[%d]: %s\n", i, psa->s[i]);
//}
//void FreeStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// free(psa->s[i]);
//}
//void InputBuffer(char* buf, int size)
//{
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, size);
//}
//int IsExit(const char* buf)
//{
// return strcmp("exit", buf) == 0;
//}
//void AddStringArray(StringArray* psa, const char* buf)
//{
// psa->s[psa->count] = (char*)malloc(strlen(buf) + 1);
// strcpy(psa->s[psa->count], buf);
// ++psa->count;
//}
//void PrintMenu()
//{
// printf("1. ๋ฌธ์์ด ์
๋ ฅ\n");
// printf("2. ๋ฌธ์์ด ์ถ๋ ฅ\n");
// printf("3. ๋ฌธ์์ด ๊ฒ์\n");
// printf("4. ๋ฌธ์์ด ์ญ์ \n");
// printf("0. ํ๋ก๊ทธ๋จ ์ข
๋ฃ\n");
// printf("\n");
//
//
//}
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while (run)
// {
// PrintMenu();
// switch (_getch())
// {
// case '1':
// {
//
// char buf[500];
// InputBuffer(buf, 500);
// AddStringArray(&sa, buf);
// }
// break;
// case '2':
// PrintStringArray(&sa);
// break;
// case '3':
// {
// char buf[500];
// printf("๊ฒ์");
// InputBuffer(buf, 500);
// for (int i = 0; i < sa.count; ++i)
// {
// if (strcmp(sa.s[i], buf) == 0)
// {
// printf("์ฐพ์ ๋ฌธ์์ด์ index: %d\n", i);
// }
// }
// }
//
// case '0':
// run = 0;
// break;
// }
//
// /*char buf[1000];
// InputBuffer(buf, 1000);
// if (IsExit(buf))
// run = 0;
// else
// {
// AddStringArray(&sa, buf);
// }*/
//
// }
//
// // PrintStringArray(&sa);
//
// FreeStringArray(&sa);
//}
# ๊ณผ์ ๋ฌธ์์ด ๊ฒ์ํ๋ฉด ์ญ์ ํ๋ ๊ฒ
# ๋ค์์ฃผ๊น์ง ์์ผ๋ก ์์ฑ ๊ฐ๋ณ ๊ณผ์
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <conio.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//void PrintStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// printf("string[%d]: %s\n", i, psa->s[i]);
//}
//void FreeStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// free(psa->s[i]);
//}
//void InputBuffer(char* buf, int size)
//{
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, size);
//}
//int IsExit(const char* buf)
//{
// return strcmp("exit", buf) == 0;
//}
//void AddStringArray(StringArray* psa, const char* buf)
//{
// psa->s[psa->count] = (char*)malloc(strlen(buf) + 1);
// strcpy(psa->s[psa->count], buf);
// ++psa->count;
//}
//void PrintMenu()
//{
// printf("1. ๋ฌธ์์ด ์
๋ ฅ\n");
// printf("2. ๋ฌธ์์ด ์ถ๋ ฅ\n");
// printf("3. ๋ฌธ์์ด ๊ฒ์\n");
//******* printf("4. ๋ฌธ์์ด ์ญ์ \n");******
// printf("0. ํ๋ก๊ทธ๋จ ์ข
๋ฃ\n");
// printf("\n");
//
//
//}
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while (run)
// {
// PrintMenu();
// switch (_getch())
// {
// case '1':
// AddStringArray(&sa, "abc");
// break;
// case '2':
// PrintStringArray(&sa);
// break;
// case '0':
// run = 0;
// break;
// }
//
// /*char buf[1000];
// InputBuffer(buf, 1000);
// if (IsExit(buf))
// run = 0;
// else
// {
// AddStringArray(&sa, buf);
// }*/
//
// }
//
// // PrintStringArray(&sa);
//
// FreeStringArray(&sa);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <conio.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//void PrintStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// printf("string[%d]: %s\n", i, psa->s[i]);
//}
//void FreeStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// free(psa->s[i]);
//}
//void InputBuffer(char* buf, int size)
//{
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, size);
//}
//int IsExit(const char* buf)
//{
// return strcmp("exit", buf) == 0;
//}
//void AddStringArray(StringArray* psa, const char* buf)
//{
// psa->s[psa->count] = (char*)malloc(strlen(buf) + 1);
// strcpy(psa->s[psa->count], buf);
// ++psa->count;
//}
//void PrintMenu()
//{
// printf("1. ๋ฌธ์์ด ์
๋ ฅ\n");
// printf("2. ๋ฌธ์์ด ์ถ๋ ฅ\n");
// printf("3. ๋ฌธ์์ด ๊ฒ์\n");
// printf("4. ๋ฌธ์์ด ์ญ์ \n");
// printf("0. ํ๋ก๊ทธ๋จ ์ข
๋ฃ\n");
// printf("\n");
//
//
//}
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while (run)
// {
// PrintMenu();
// switch (_getch())
// {
// case '1':
// break;
// case '0':
// run = 0;
// break;
// }
//
// /*char buf[1000];
// InputBuffer(buf, 1000);
// if (IsExit(buf))
// run = 0;
// else
// {
// AddStringArray(&sa, buf);
// }*/
//
// }
//
// // PrintStringArray(&sa);
//
// FreeStringArray(&sa);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//void PrintStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// printf("string[%d]: %s\n", i, psa->s[i]);
//}
//void FreeStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// free(psa->s[i]);
//}
//void InputBuffer(char* buf, int size)
//{
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, size);
//}
//int IsExit(const char* buf)
//{
// return strcmp("exit", buf) == 0;
//}
//void AddStringArray(StringArray* psa, const char* buf)
//{
// psa->s[psa->count] = (char*)malloc(strlen(buf) + 1);
// strcpy(psa->s[psa->count], buf);
// ++psa->count;
//}
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while (run)
// {
// char buf[1000];
// InputBuffer(buf, 1000);
// if (IsExit(buf))
// run = 0;
// else
// {
// AddStringArray(&sa, buf);
// }
//
// }
//
// PrintStringArray(&sa);
// PrintStringArray(&sa);
// PrintStringArray(&sa);
//
// FreeStringArray(&sa);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//void PrintStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// printf("string[%d]: %s\n", i, psa->s[i]);
//}
//void FreeStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// free(psa->s[i]);
//}
//void InputBuffer(char* buf, int size)
//{
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, size);
//}
//int IsExit(const char* buf)
//{
// return strcmp("exit", buf) == 0;
//}
//void AddStringArray(StringArray* psa, const char* buf)
//{
// psa->s[psa->count] = (char*)malloc(strlen(buf) + 1);
// strcpy(psa->s[psa->count], buf);
// ++psa->count;
//}
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while (run)
// {
// char buf[1000];
// InputBuffer(buf, 1000);
// if (IsExit(buf))
// run = 0;
// else
// {
// AddStringArray(&sa, buf);
// }
//
// }
//
// PrintStringArray(&sa);
// PrintStringArray(&sa);
// PrintStringArray(&sa);
//
// FreeStringArray(&sa);
//}
// StringArray ๋ง์ ์ฝ๋๋ ์ํ ์ ์ธํ๋ค
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//void PrintStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// printf("string[%d]: %s\n", i, psa->s[i]);
//}
//void FreeStringArray(StringArray* psa)
//{
// for (int i = 0; i < psa->count; ++i)
// free(psa->s[i]);
//}
//
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while (run)
// {
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// if (strcmp("exit", buf) == 0)
// run = 0;
// else
// {
// sa.s[sa.count] = (char*)malloc(strlen(buf) + 1);
// strcpy(sa.s[sa.count], buf);
// ++sa.count;
// }
//
// }
//
// PrintStringArray(&sa);
//
// FreeStringArray(&sa);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while (run)
// {
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// if (strcmp("exit", buf) == 0)
// run = 0;
// else
// {
// sa.s[sa.count] = (char*)malloc(strlen(buf) + 1);
// strcpy(sa.s[sa.count], buf);
// ++sa.count;
// }
//
// }
//
// for (int i = 0; i < sa.count; ++i)
// printf("string[%d]: %s\n", i, sa.s[i]);
//
// for (int i = 0; i < sa.count; ++i)
// free(sa.s[i]);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//struct StringArray // ๊ตฌ์กฐ์ฒด ์ ์
//{
// char* s[100]; //๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ
// int count = 0;
//};
//int main()
//{
// //*char* s1;
// //char* s2;
// StringArray sa;
// StringArray sa2;
// StringArray sa3;
// int run = 1;
//
// while(run)
// {
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// if (strcmp("exit", buf) == 0)
// run = 0;
// else
// {
// sa.s[sa.count] = (char*)malloc(strlen(buf) + 1);
// strcpy(sa.s[sa.count], buf);
// ++sa.count;
// }
//
// }
//
// for (int i = 0; i < sa.count; ++i)
// printf("string[%d]: %s\n", i, sa.s[i]);
//
// for (int i = 0; i < sa.count; ++i)
// free(sa.s[i]);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//int main()
//{
// //*char* s1;
// //char* s2;
// char* s[100] = { NULL };
// int count = 0;
//
//
// for ( ; ; )
// {
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// if (strcmp("exit", buf) == 0)
// break;
//
// s[count] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[count], buf);
// ++count;
// }
//
// for (int i = 0; i < count; ++i)
// printf("string[%d]: %s\n", i, s[i]);
//
// for (int i = 0; i < count; ++i)
// free(s[i]);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//int main()
//{
// //*char* s1;
// //char* s2;
// char* s[100] = { NULL };
// int count = 0;
//
//
// for (int i = 0; i < 3; ++i)
// {
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[count] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[count], buf);
// ++count;
// }
//
// for (int i = 0; i < count; ++i)
// printf("string[%d]: %s\n", i, s[i]);
//
// for (int i = 0; i < count; ++i)
// free(s[i]);
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//int main()
//{
// //*char* s1;
// //char* s2;
// char* s[100] = { NULL };
// int count = 0;
//
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[count] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[count], buf);
// ++count;
//
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[count] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[count], buf);
// ++count;
//
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[count] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[count], buf);
// ++count;
//
// for (int i = 0; i < count; ++i)
// printf("string[%d]: %s\n", i, s[i]);
//
// for (int i = 0; i < count; ++i)
// free(s[i]);
//
//
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//int main()
//{
// //*char* s1;
// //char* s2;
// char* s[100] = { NULL };
//
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[0] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[0], buf);
//
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[1] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[1], buf);
//
// printf("string: %s\n", s[0]);
// printf("string: %s\n", s[1]);
// printf("string: %s\n", s[2]);
//
// free(s[1]);
// free(s[2]);
//
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//int main()
//{
// //*char* s1;
// //char* s2;
// char* s[2] = { NULL };
//
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[1] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[1], buf);
//
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// s[2] = (char*)malloc(strlen(buf) + 1);
// strcpy(s[2], buf);
//
// printf("string: %s\n", s[1]);
// printf("string: %s\n", s[2]);
//
// free(s[1]);
// free(s[2]);
//
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//int main()
//{
// //1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// // 2. ํ๋ฉ๋ชจ๋ฆฌ ์์ฑํ๊ณ ๋ฌธ์์ด ๋ณต์ฌ
// char* s = NULL;
// s = (char*)malloc(strlen(buf) + 1);
// strcpy(s, buf);
// //3. ๋ฌธ์์ด ์ถ๋ ฅ
// printf("string: %s\n", buf);
// printf("string: %s\n", s);
// // 4. ํ๋ฉ๋ชจ๋ฆฌ ์ญ์
// free(s);
//
//}
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//int main()
//{
//
// char buf[1000]; //1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
// gets_s(buf, 1000);
// char* s = NULL; //1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
// s = (char*)malloc( strlen(buf) + 1 );
// s[0] = buf[0];
// s[1] = buf[1];
// s[2] = buf[2];
// s[3] = buf[3];
// s[4] = buf[4];
// s[5] = buf[5];
//
// printf("string: %s\n", buf);
// printf("string: %s\n", s);
//
//}
//#include <stdio.h>
//#include <stdlib.h>
//int main()
//{
//
// char buf[1000]; //1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
// gets_s(buf, 1000);
// char* s = NULL; //1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
// s = (char*)malloc(6);
// s[0] = buf[0];
// s[1] = buf[1];
// s[2] = buf[2];
// s[3] = buf[3];
// s[4] = buf[4];
// s[5] = buf[5];
//
// printf("string: %s\n", buf);
// printf("string: %s\n", s);
//
//}
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <string.h>
//#include <stdlib.h>
//
//int main()
//{
// char* sarr[1000] = { 0 };
// int count = 0;
//
// while (1)
// {
// char buf[1000]; //1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
//
// printf("๋ฌธ์์ด ์
๋ ฅ:");
//
// gets_s(buf, 1000); //1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
// if (strcmp("exit", buf) == 0)
// break;
//
// printf("string : %s\n", buf); //3. ๋ฌธ์์ด ์ถ๋ ฅ
//
// char* s = (char*)malloc(strlen(buf) + 1);
//
// strcpy(s, buf);
//
// sarr[count++] = s;
// }
//
// for (int i = 0; i < count; ++i)
// printf("[%d] : %s\n", i, sarr[i]);
//
// for (int i = 0; i < count; ++i)
// free(sarr[0]);
//}
//#pragma warning (disable:4996)
//#include <stdlib.h>
//#include <string.h>
//#include <stdio.h>
//int main()
//{
// char* sarr[1000] = { 0 };
// int count = 0;
// while (1)
// {
// char buf[1000];
// printf("๋ฌธ์์ด ์
๋ ฅ:");
// gets_s(buf, 1000);
// if (strcmp("exit", buf) == 0);
// break;
//
// printf("string: %s\n", buf);
//
// char* s = (char*)malloc(strlen(buf) + 1);
//
// strcpy(s, buf);
//
// sarr[count++] = s;
//
// }
//
// for (int i = 0; i < count; ++i)
// printf("[%d]: %s\n",i , sarr[i]);
//
// for (int i = 0; i < count; ++i)
// free(sarr[0]);
//}
////1. ๋ฌธ์์ด์ ์
๋ ฅ ๋ฐ์
// // 2. ํ๋ฉ๋ชจ๋ฆฌ ์์ฑํ๊ณ ๋ฌธ์์ด ๋ณต์ฌ
// //3. ๋ฌธ์์ด ์ถ๋ ฅ
// // 4. ํ๋ฉ๋ชจ๋ฆฌ ์ญ์