示例#1
0
void main()
{
	char s[] = "reverse this";
//	rev(s);
	revstr(s);
	printf("\nreversed string = %s\n", s);
}
void strwordsinrev(char *input)
{
	char b[100], *temp, *str;
	int count = 0;
	temp = input;
	while (*temp)
	{
		while (*temp != ' ' && *temp != '\0')
		{
			b[count] = *temp;
			temp++;
			count++;
		}
		b[count] = '\0';
		count = 0;
		revstr(b);
		str = b;
		while (*str)
		{
			*input = *str;
			str++;
			input++;
		}
		while (*input == ' ')
		{
			input++;
		}
		temp = input;
	}
}
/*
 * in-place reverse of the string that starts at `src`
 */
static void revstrml(char *src)
{
  char *cur, *prev;

  cur = strchr(src, '\n');
  prev = src;

  while (cur != NULL) {
    if(cur != prev)
      revstr(prev, cur - 1);
    prev = ++cur;
    cur = strchr(cur, '\n');
  }

  if(*(src + strlen(src) - 1) != '\n')
    revstr(prev, src + strlen(src) - 1);
}
示例#4
0
int main(int argc,char**argv)
{
	//char *str =  "12345";
	//以这种方式定义,str指向字符串常量区的字符串,而如果后面试图修改常量区域的东西,会出现段错误
	//char str[] = "12345";
	//以这种方式定义是在栈上定义一块空间并将常量区的字符串拷贝一份存放到栈中的数组中,修改栈上的东西是可以的。
	char str[] = "12345";
	printf("%s ",revstr(str,strlen(str)));
	return 0;
}
示例#5
0
int getWeight(char *szID)
{
  char   *szBreak  = revstr(szID, WEIGHTDELIM); 
  double dWeight   = 0.0;
  char   *pcError  = NULL;
  
 
  if(szBreak != NULL){
    dWeight = strtod(szBreak + 1, &pcError);
    if(*pcError != '\0'){
      fprintf(stderr, "Sequence weight format error %s %s\n",szID,szBreak + 1);
      fflush(stderr);
    }
  }
  else{
    dWeight = 1.0;
  }

  return (int) floor(dWeight + 1.0e-7);
}
示例#6
0
char	*play(t_platine *p)
{
  char	*str;
  if (p->cmd[p->index][0] == '#')
    str = strdup("shrrrck");
  else
    str = remove_cut(strdup(p->cmd[p->index]));
  if (p->lowpass == 1)
    str = filter_lowpass(str);
  if (p->highpass == 1)
    str = filter_highpass(str);
  if (p->doubl == 1)
    str = fx_double(str);
  if (p->flanger == 1)
    str = flanger(str);
  if (p->echo == 1)
    str = fx_echo(str);
  reset_all_fx(p);
  if (p->reversed == 1)
    return (revstr(str));
  return (str);
}
示例#7
0
文件: Misc.c 项目: EnderUNIXSDT/Aget
void parse_url(char *url, struct request *req)
{
	char *s;
	int i, j, k;

	i = j = k = 0;
	s = url;
	if ((strncmp(url, "ftp://", 6)) == 0) {
		fprintf(stderr, "Error: Currently Aget doesn't support FTP requests...\n");
		exit(1);
	} else
	if ((strncmp(url, "http://", 7)) != 0) {
		fprintf(stderr, "Error: URL should be of the form http://...\n");
		exit(1);
	}

	if (req->port == 0) {
		req->port = 80;
		req->proto = PROTO_HTTP;
	}


	s = url + 7; 	/* Jump pass http:// part	*/
	for (i = 0; *s != '/'; i++, s++) {
		if (i > MAXHOSTSIZ) {
			fprintf(stderr, "Error: Cannot get hostname from URL...\n");
			exit(1);
		}
		if (*s == ':') {	/* If user/pass is supplied like; http://murat:[email protected]/url.html */
			while(*s != '/') {
				req->username[j++] = *--s;
				i--;
			}
			req->username[--j] = '\0';
			revstr(req->username);
			while(1) {
				if (*s == ':') {
					while(*s != '@') {
						if (k > MAXBUFSIZ) {
							fprintf(stderr, "Error: Cannot get password from URL...\n");
							exit(1);
						}
						req->password[k++] = *++s;
					}
					break;
				}
				s++;
			}
			req->password[--k] = '\0';
		}
		req->host[i] = *s;
	}
	req->host[i] = '\0';
	for (i = 0; *s != '\0'; i++, s++) {
		if (i > MAXURLSIZ) {
			fprintf(stderr, "Error: Cannot get remote file name from URL...\n");
			exit(1);
		}
		req->url[i] = *s;
	}
	req->url[i] = '\0';
	--s;
	for (i = 0; *s != '/'; i++, s--) {
		if (i > MAXBUFSIZ) {
			fprintf(stderr, "Error: Cannot get local file name from URL...\n");
			exit(1);
		}
		req->file[i] = *s;
	}
	req->file[i] = '\0';
	revstr(req->file);

}
void str_words_in_rev(char *input, int len)
{
	strwordsinrev(input);
	revstr(input);
}
示例#9
0
void	infin(char *str1, char *str2)
{
  int	flag1;
  int	flag2;
  char	*added;
  char	*mined;
  int	flagsup;
 
  flag1 = 0;
  flag2 = 0;
  while (*str1 == '-')
    {
      flag1 = 1;
      str1++;
    }
  while (*str2 == '-')
  {
    flag2 = 1;
    str2++;
  }
  if (!flag1 && !flag2)
    {
      revstr(str1);
      revstr(str2);
      added = add(str1, str2);
      revstr(added);
      while (*added == '0' && *(added + 1) != '\0')
	added++;
      my_putstr(added);
    }
  else if (flag1 && flag2)
    {
      revstr(str1);
      revstr(str2);
      added = add(str1, str2);
      revstr(added);
      while (*added == '0' && *(added + 1) != '\0')
	added++;
      if (added[0] != '0' || my_strlen(added) != 1)
	my_putchar('-');
      my_putstr(added);
    }
  /* -4 2 -2 4*/
  else if (flag1 && !flag2)
    {
      while (*str1 == '0' && *(str1 + 1) != '\0')
	str1++;
      while (*str2 == '0' && *(str2 + 1) != '\0')
	str2++;
      flagsup = is_sup(str1, str2);
      revstr(str2);
      revstr(str1);

      /*-4 3 */
      if (flagsup)
	{
	  mined = min(str1, str2);
	  revstr(mined);
	  while (*mined == '0' && *(mined + 1) != '\0')
            mined++;
	  if (mined[0] != '0' || my_strlen(mined) != 1)
	    my_putchar('-');
	  my_putstr(mined);
	}
      /*-3 4 */
      else
	{
	  mined = min(str2, str1);
	  revstr(mined);
	  while (*mined == '0' && *(mined + 1) != '\0')
	    mined++;
	  my_putstr(mined);
	}
    }
  else if (!flag1 && flag2)
    {
      while (*str1 == '0' && *(str1 + 1) != '\0')
	str1++;
      while (*str2 == '0' && *(str2 + 1) != '\0')
	str2++;
      flagsup = is_sup(str1, str2);
      revstr(str2);
      revstr(str1);
      /* 4 -3*/
      if (flagsup)
	{
	  mined = min(str1, str2);
	  revstr(mined);
	  while (*mined == '0' && *(mined + 1) != '\0')
	    mined++;
	  my_putstr(mined);
	}
      /*-3 4 */
      else
	{
	  mined = min(str2, str1);
	  revstr(mined);
	  while (*mined == '0' && *(mined + 1) != '\0')
	    mined++;
	  if (mined[0] != '0' || my_strlen(mined) != 1)
	    my_putchar('-');
	  my_putstr(mined);
	}
    }
}
示例#10
0
int main(int argc, char **argv)
{
  int sockfd, acc_fd;
  struct sockaddr_in server;
  struct sockaddr_in client;
  int sin_size, port;
  size_t nbytes;
  char buffer[BUFSIZ];

  signal(SIGCHLD, sighandler);

  if (argc != 2) {
    fprintf(stderr, "Usage: %s port\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  port = atoi(argv[1]);
  if (port < 0 || port > 65535) {
    fprintf(stderr, "Invalid port %d\n", port);
    exit(EXIT_FAILURE);
  }

  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "socket() error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }

  memset((void *)&server, 0, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = htonl(INADDR_ANY);
  server.sin_port = htons(port);

  if (bind(sockfd, (struct sockaddr*)&server, 
	   sizeof(struct sockaddr)) == -1) {
    fprintf(stderr, "bind() error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }

  if (listen(sockfd, 5) == -1) {
    fprintf(stderr, "listen() error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }

  for (;;) {
    sin_size = sizeof(struct sockaddr_in);
    if ((acc_fd = accept(sockfd, (struct sockaddr*)&client, 
			 &sin_size)) == -1) {
      fprintf(stderr, "accept() error: %s\n",
	      strerror(errno));
      exit(EXIT_FAILURE);
    }
    int new_fd = acc_fd;
    if (fork() == 0) {
      for (;;) {
	printf("Connection from %s:%d\n", inet_ntoa(client.sin_addr),
	       ntohs(client.sin_port));
	if ((nbytes = recv(new_fd, buffer, BUFSIZ, 0)) == -1) {
	  fprintf(stderr, "recv() error: %s\n", strerror(errno));
	  exit(EXIT_FAILURE);
	}
	buffer[nbytes] = '\0';
	if (!strcmp(buffer, EXIT)) {
	  printf("Client %s:%d exited, goodbye\n", 
		 inet_ntoa(client.sin_addr), 
		 ntohs(client.sin_port));
	  exit(EXIT_SUCCESS);
	}
	printf("Client send: %s\n", buffer);
	revstr(buffer);
	send(new_fd, buffer, strlen(buffer), 0);

      }
    }
  }

  close(sockfd);

  exit(EXIT_SUCCESS);
}
示例#11
0
文件: Misc.c 项目: fangang190/canary
void parse_url(char *url, struct request *req)
{
	char *s;
	int i, j, k;

	i = j = k = 0;
	s = url;
	if ((strncmp(url, "https://", 8)) == 0) {
		fprintf(stderr, "Error: Currently Aget doesn't support HTTPS requests...\n");
		exit(1);
	} else if ((strncmp(url, "ftp://", 6)) == 0) {
		req->port = (req->port == 0 ? 21 : req->port);
		req->proto = PROTO_FTP;
	} else if ((strncmp(url, "http://", 7)) == 0) {
		req->port = (req->port == 0 ? 80 : req->port);
		req->proto = PROTO_HTTP;
	} else {
		fprintf(stderr, "Error: No protocol specified (http:// or ftp://)...\n");
		exit(1);
	}

	if ((strncmp(url, "http://", 7)) != 0 && req->proto == PROTO_HTTP) {
		fprintf(stderr, "Error: URL should be of the form http://...\n");
		exit(1);
	}

	if ((strncmp(url, "ftp://", 6)) != 0 && req->proto == PROTO_FTP) {
		fprintf(stderr, "Error: URL should be of the form ftp://...\n");
		exit(1);
	}

	s = (req->proto == PROTO_HTTP ? url + 7 : url + 6); 	/* Jump pass http://  or ftp:// part depending on the protocol */
	for (i = 0; *s != '/'; i++, s++) {
		if (i > MAXHOSTSIZ) {
			fprintf(stderr, "Error: Cannot get hostname from URL...\n");
			exit(1);
		}
		if (*s == ':') {	/* If username:password is supplied: http://naveen:[email protected]/file */
			while(*s != '/') {
				req->username[j++] = *--s;
				i--;
			}
			req->username[--j] = '\0';
			revstr(req->username);

			while(*s != ':') s++;	/* Skip past user name --Naveen */

			while(1) {
				if (*s == ':') {
					while(*s != '@') {
						if (k > MAXBUFSIZ) {
							fprintf(stderr, "Error: Cannot get password from URL...\n");
							exit(1);
						}
						req->password[k++] = *++s;
					}
					break;
				}
				s++;
			}
			req->password[--k] = '\0';
		}
		req->host[i] = *s;
	}
	req->host[i] = '\0';
	for (i = 0; *s != '\0'; i++, s++) {
		if (i > MAXURLSIZ) {
			fprintf(stderr, "Error: Cannot get remote file name from URL...\n");
			exit(1);
		}
		req->url[i] = *s;
	}
	req->url[i] = '\0';
	--s;
	for (i = 0; *s != '/'; i++, s--) {
		if (i > MAXBUFSIZ) {
			fprintf(stderr, "Error: Cannot get local file name from URL...\n");
			exit(1);
		}
		req->file[i] = *s;
	}
	req->file[i] = '\0';
	revstr(req->file);

	/* Required for FTP */
	if (strlen(req->username) <= 0)
		strncpy(req->username, ftpanonymoususer, MAXBUFSIZ - 2);
	if (strlen(req->password) <= 0)
		strncpy(req->password, ftpanonymouspass, MAXBUFSIZ - 2);
}
示例#12
0
文件: 002.c 项目: ChinaChenp/devtools
int main(int argc, char *argv[])
{
	printf("%s-->%s\n", argv[1], revstr(argv[1]));

	return 0;
}