Example #1
0
int main(int argc, char * argv[])
{
	int x = 0, z = 1;

	if (argv[1] != NULL)
	{
		do
		{
			if (strcmp(argv[z], help) == 0)
			{
				f_help();
			}
			if (strcmp(argv[z], print) == 0)
			{
				x = 0;
				f_print(x);
			}
			if (strcmp(argv[z], removeall) == 0)
			{
				f_removeall();
			}
			if (strcmp(argv[z], add) == 0)
			{
				f_add();
			}
			if (strcmp(argv[z], remov) == 0)
			{
				f_remov();
			}
			if (strcmp(argv[z], findname) == 0)
			{
				x = 0;
				f_find(x);
			}
			if (strcmp(argv[z], findsname) == 0)
			{
				x = 1;
				f_find(x);
			}
			if (strcmp(argv[z], findlname) == 0)
			{
				x = 2;
				f_find(x);
			}
			if (strcmp(argv[z], findgr) == 0)
			{
				x = 3;
				f_find(x);
			}
			if (strcmp(argv[z], sortname) == 0)
			{
				x = 1;
				f_sort(x);
			}
			if (strcmp(argv[z], sortsname) == 0)
			{
				x = 2;
				f_sort(x);
			}
			if (strcmp(argv[z], sortlname) == 0)
			{
				x = 3;
				f_sort(x);
			}
			if (strcmp(argv[z], sortgr) == 0)
			{
				x = 4;
				f_sort(x);
			}
			if (strcmp(argv[z], kol) == 0)
			{
				x = 1;
				f_print(x);
			}
			z++;
		} while (argv[z] != NULL);
	}

	return 0;
}
Example #2
0
//
// This program is a driver to test the first assignment functions.
//  The first 4 are tested.
//
int main(int argc, char** argv)
{
  bool ans;
  int armstrong_test = 8;  // true
  char brackets[5] = "[[]]";  // true
  int perfect_test = 28; // true
  int rotate_test = 1234;
  int r = 1;
  int rotate_test_solution = 4123;
  int rotate_test_ans = 0;
  char pattern_test[] = "ana";
  char text_test[] = "ana ate the banana";
  int str_search_solution = 3;
  int str_search_ans =0;
  int collatz_count_ans = 0;
  int collatz_count_solution = 7;
  int collatz_test = 20;
  int f_array_test = 15;
  char string_1[6] = "HELLO";
  char string_2[3] = "hi";
  char string_result[10];
  char string_ans[10] = "hiHELLOhi";
  int num1=14, num2=13, num3=12;
  int ascending [3] = {0};
  int ascending_ans[3] = {12,13,14};
  int cube_sum_this_num = 54;


  printf("Testing functions:\n");


  //1
  ans = f_armstrong(armstrong_test);
  text_output(1, ans==true);

  //2
  ans = f_brackets(brackets);
  text_output(2, ans==true);

  //3
  ans = f_perfect(perfect_test);
  text_output(3, ans==true);

  //4
  rotate_test_ans = f_rotate(rotate_test,r);
  if(rotate_test_ans == rotate_test_solution)
  {
      ans = true;
  }
  else
  {
      ans = false;
  }
  text_output(4,ans);

  //5
  str_search_ans = f_str_search(&pattern_test, &text_test);
  if(str_search_ans == str_search_solution)
  {
      ans = true;
  }
  else
  {
      ans = false;
  }
  text_output(5,ans);

  //6
  collatz_count_ans = f_collatz_count(collatz_test);
    if(collatz_count_ans == collatz_count_solution)
    {
        ans = true;
    }
    else
    {
        ans = false;
    }
    text_output(6,ans);

    //7
    text_output(7, ans);
    f_array(f_array_test);

    //8
    f_strings(&string_1, &string_2, &string_result);
    printf("The input strings were '%s' and '%s'.\n", string_1, string_2);
    printf("The answer should be '%s'\nYour answer is '%s'\n\n", string_ans, string_result);

    //9
    f_sort(num1, num2, num3, &ascending);
    if (ascending[0]==ascending_ans[0] && ascending[1]==ascending_ans[1] && ascending[2]==ascending_ans[2])
    {
        ans = true;
    }
    else
    {
        ans = false;
    }
    text_output(9,ans);

    //10
    if ((f_cubes_sum(cube_sum_this_num)[0] + f_cubes_sum(cube_sum_this_num)[1]) == cube_sum_this_num)
    {
        ans=true;
    }
    else
    {
        ans=false;
    }
    text_output(10,ans);
}
Example #3
0
int f_add()
{
	int sh = 0, a = 0, l = 0, y = 0, x = -1, z = 0, i;
	struct str *s;
	FILE *file;
	char proverka[11] = "0123456789";

	file = fopen("file.txt", "rb+");
	if (!file)
	{
		printf("\nОшибка файла\n\n");
		return 1;
	}

	puts("\nВведите количество строк, которые хотите добавить");
	do
	{
		if (sh == 1)
		{
			fflushstdin();
		}
		if (!scanf("%d", &a) || (a < 1) || (a > 1000))
		{
			puts("Ошибка ввода. Введите заново");
		}
		sh = 1;
	} while (!a || (a < 1) || (a > 1000));
	sh = 0;

	puts("\nВведите max символьную длину имя, фамилии, отчества или группы (min 15)");
	do
	{
		if (sh == 1)
		{
			fflushstdin();
		}
		if (!scanf("%d", &l) || (l < 15) || (l > 1000))
		{
			puts("Ошибка ввода. Введите заново");
		}
		sh = 1;
	} while (!l || (l < 15) || (l > 1000));
	sh = 0; l += 30;

	//Выделение памяти
	s = (struct str *)malloc(a * sizeof(struct str));
	if (s == NULL)
	{
		printf("\nОшибка памяти\n");
		return 1;
	}
	memory(a, l, s);

	fseek(file, 0, 2);

	for (y = 0; y < a; y++)
	{
		fflushstdin();

		do
		{
			printf("\nВведите имя %d-го человека\n", y + 1);
			sh = 0;
			fgets(s[y].name, l, stdin);
			for (z = 0; z < 10; z++)
			{
				for (i = 0; i < l; i++)
				{
					if (proverka[z] == s[y].name[i])
					{
						puts("Ошибка ввода. Введите заново");
						sh = 1;
						free(s[y].name);
						s[y].name = (char *)calloc(l, sizeof(char));
					}
				}
			}
		}while (sh == 1);

		do
		{
			printf("\nВведите фамилию %d-го человека\n", y + 1);
			sh = 0;
			fgets(s[y].sname, l, stdin);
			for (z = 0; z < 10; z++)
			{
				for (i = 0; i < l; i++)
				{
					if (proverka[z] == s[y].sname[i])
					{
						puts("Ошибка ввода. Введите заново");
						sh = 1;
						free(s[y].sname);
						s[y].sname = (char *)calloc(l, sizeof(char));
					}
				}
			}
		}while (sh == 1);

		do
		{
			printf("\nВведите отчество %d-го человека\n", y + 1);
			sh = 0;
			fgets(s[y].lname, l, stdin);
			for (z = 0; z < 10; z++)
			{
				for (i = 0; i < l; i++)
				{
					if (proverka[z] == s[y].lname[i])
					{
						puts("Ошибка ввода. Введите заново");
						sh = 1;
						free(s[y].lname);
						s[y].lname = (char *)calloc(l, sizeof(char));
					}
				}
			}
		}while (sh == 1);

		printf("\nВведите группу %d-го человека\n", y + 1);
		fgets(s[y].gr, l, stdin);

		fprintf(file, "%s %s %s %s", s[y].name, s[y].sname, s[y].lname, s[y].gr);
	}

	fclose(file);

	//Очищение памяти
	fmemory(a, l, s);
	free(s);

	f_sort(x);

	return 0;
}