- 1
- 2
- 3
- 4
- 5
// Делаем из префикса количество хостов (без .0 и броадкаста)
numips = pow(2.0, (double)(32 - slashnet)) - 2;
// Делаем префикс из маски сети
slashnet = 32 - ((int)log2((double)(0xFFFFFFFF - vnetconfig->nm)) + 1);Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+136
// Делаем из префикса количество хостов (без .0 и броадкаста)
numips = pow(2.0, (double)(32 - slashnet)) - 2;
// Делаем префикс из маски сети
slashnet = 32 - ((int)log2((double)(0xFFFFFFFF - vnetconfig->nm)) + 1);Всё те же, всё оттуда же...
+136
int check_process(pid_t pid, char *search) {
  char file[1024], buf[1024];
  FILE *FH=NULL;
  int rc, ret=0;
  snprintf(file, 1024, "/proc/%d/cmdline", pid);
  rc = check_file(file);
  if (!rc) {
    // cmdline exists
    ret = 1;
    if (search) {
      // check if cmdline contains 'search'
      FH = fopen(file, "r");
      if (FH) {
	bzero(buf, 1024);
	while(fgets(buf, 1024, FH)) {
	  char *p;
	  while((p = memchr(buf, '\0', 1024))) {
	    *p = 'X';
	  }
	  buf[1023] = '\0';
	  if (strstr(buf, search)) {
	    ret = 0;
	  }
	}
	fclose(FH);
      }
    } else {
      ret = 0;
    }
  } else {
    ret = 1;
  }
  return(ret);
}Суровые калифорнийские студенты суровы.
+136
if (init) {
} else {
  // thread is not initialized, run first time local state setup
  ...
}
+136
memset( fc->key, 0, KEY_LEN+1);
memset( fc->value, 0, VALUE_LEN+1);
strncpy(fc->key, key, strlen( key) + 1);
strncpy(fc->value, value,strlen( value) + 1);совершенное непонимание работы ф-ии strncpy
+136
#define alias long
#define int b
#define cat 2
alias int=cat;
#undef int
int a$(int b)
{
  return 1;
}
main()
{
  return a$(b)+1;
}
            Здесь нет С++, зато есть... bash!
На что спорим, что код возврата программы будет 1?
        
+136
public string generateEMail()
		{
			string res;
			int i = PersonName.IndexOf(" ");
			char[] str1 = new char[i];
			PersonName.CopyTo(0, str1, 0, i);
			string str11 = new string(str1);
			char[] str2 = new char[PersonName.Length - i - 1];
			PersonName.CopyTo(i + 1, str2, 0, PersonName.Length - i - 1);
			string str22 = new string(str2);
			res = str11.ToString() + "." + str22.ToString();
			if (res.Length > 20)
			{
				str1 = new char[20];
				res.CopyTo(0, str1, 0, 20);
				res = new string(str1);
			}
			res += "@domain.ua";
			return res;
		}Вот вам шаблон для получения емейла из имени и фамилии сотрудника.
+136
/// <summary>Read-Only property. Gets the Age.</summary>
public Int32 Age {
	get {
		Int32 age = 0;
		if(this.dateOfBirth != DateTime.MaxValue){
			String temp = (DateTime.Now.Subtract(this.dateOfBirth).TotalDays / 365).ToString();
			age = Convert.ToInt32(temp.Substring(0, temp.IndexOf(".")));
		}
		return (age);
	}
}вот только одно не понимаю -- мочему Int32?
+136
public bool IsPositiveNumber(String strNumber)
{
    Regex objNotPositivePattern = new Regex("[^0-9.]");
    Regex objPositivePattern = new Regex("^[.][0-9]+$|[0-9]*[.]*[0-9]+$");
    Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
    return !objNotPositivePattern.IsMatch(strNumber) &&
    objPositivePattern.IsMatch(strNumber) &&
    !objTwoDotPattern.IsMatch(strNumber);
}Валидатор :)
+136
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
struct thread_arg
{
	int a;
	int b;
	int c;
	double d;
};
	
void *ret_x1(void *arg)
{
		
	struct thread_arg targ = *(struct thread_arg *)arg;
	double x1;
	x1 = (-targ.b + sqrt(targ.d)) / (2*targ.a);
	fprintf(stderr, "x1 = %f\n", x1);
	return NULL;
}
void *ret_x2(void *arg)
{
	struct thread_arg targ = *(struct thread_arg*)arg;
	double x2;
	x2 = (-targ.b - sqrt(targ.d)) / (2*targ.a);
	
	fprintf(stderr, "x2 = %f\n", x2);
	
	return NULL;
}
int main(void)
{
	pthread_t thread1, thread2;
	struct thread_arg args;
	fprintf(stderr, "Enter a, b and c\n");
	scanf("%d %d %d", &args.a, &args.b, &args.c);
	
	args.d = args.b*args.b - 4*args.a*args.c;
	if(args.d < 0)
	{
		fprintf(stderr,"There is no roots\n");
		return 0;
	}
	else
	{
		if(pthread_create(&thread1, NULL, &ret_x1, &args) != 0)
		{
			fprintf(stderr, "Error1\n");
			return 1;
		}
		if(pthread_create(&thread2, NULL, &ret_x2, &args) != 0)
		{
			fprintf(stderr, "Error2\n");
			return 1;
		}
		pthread_join(thread1, NULL);
		pthread_join(thread2, NULL);
	}
	return 0;
		
}Многопоточное решение квадратного уравнения...
+136
вавап
овап