小试geany

geany这个工具在windows下使用居然有点略卡,编译过程,avast报警。。总体来说还比较好用,gnu c比ansi c好用不少。

小程序取自C程序设计语言里的题目2.4,实现了将字符串1中与字符串2中的相同字符剔除。

/*
 * squeeze.c
 * 
 * Copyright 2014 Administrator <fishland>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * 
 */


#include <stdio.h>
#include <string.h>
#include <malloc.h>

int find(char*str, char c)
{
	int strlength = strlen(str);
	int i;
	int ret = -1;
	for(i = 0; i != strlength; i++)
	{
		if(str[i] == c)
		{
			ret = i;
		}	
	}
	return ret;
}

int del_char(char* str, int ofs)
{
	int i, ret = 0;
	int strlength = strlen(str);
	
	if(ofs > strlength)
	{
		printf("invalid value..!\n");
		ret = -1;
	}
	for(i = ofs; i < strlength; i++)
	{
		str[i] = str[i + 1];
	}
	return ret;
}

void squeeze(char* str1, char* str2)
{
	if(str1 == NULL || str2 == NULL)
	{
		printf("error..!\n");
	}
	
	int strlength = strlen(str2);
	char* col = (char*)malloc(strlength);
	int i, j;
	for(i = 0; i != strlength; i++)
	{
		while((j = find(str1, str2[i])) != -1)
			del_char(str1, j); 
	}
	free(col);
}

int main(int argc, char **argv)
{
	char str1[] = "aaabbbcccdddfdasfjlajflajlajlfasflasflasjlas";
	char str2[] = "afs";
	printf("str1 = %s\n", str1);
	printf("str2 = %s\n", str2);
	printf("squeezing..!\n");
	squeeze(str1, str2);
	printf("str1 is squeezed to %s\n", str1);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值