个人项目(1)

最近在八戒网注册了账号,由于学习比较忙,虽然希望自己可以在学习之余,可以在网上获取一些小型项目以此来练手and get some money extra !!!

很是庆幸在端午节的今天可以接到一个适合自己的小型项目;

 

项目要求:

------------------------------------------------------------------------------------------------------------------------------

一个txt文本

1.254.165.106 abc 1
1.237.143.246 abc 1
1.34.245.143 abc 1234

例如这样的txt
整理后变成
1
1234

就是把最后一行前面的删掉

第二个功能 一个txt文本如下

1 60.208.171.** 80 匿名 2013-6-12 10:55:00 山东省济南市联通
2 120.68.31.1** 80 匿名 2013-6-12 11:02:00 新疆伊犁州电信

把他整理成
60.208.171.1 60.208.171.255
120.68.31.1 120.68.31.255

--------------------------------------------------------------------------------------------------------------------------------

 

解决方案:

1.关于文件操作,本人比较擅长C语言编程,所以决定用C语言文件操作编程的相关知识去解决问题!!!!当然事实证明虽然自己在C语言编程相当自信,可是依旧需要翻阅相关书籍

  and 访问其他人的经验的资料;

2. 解决过程:首先在console模式下搭建问题解决的基本框架,

       然后采用MFC编程进行可视化程序设计,以此给客户提供跟人性化的体验和帮助;

3.现在可以上具体代码:

 

// DO_File.h

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

void Show_IP(char IP[][4])
{
printf("%s.%s.%s.%s", IP[0], IP[1], IP[2], IP[3]);
}


void Read_one_Line(FILE *fp_src, char IP[][4])
{
int i;
char buf;

while(buf != ' ')
{
fread(&buf, 1, 1, fp_src);
}

i = 0;
// fseek(fp_src, 1, SEEK_CUR);
memset(IP[0],0,sizeof(IP[0]));
fread(&buf, 1, 1, fp_src);
while(buf != '.')
{
IP[0][i] = buf;
i++;
fread(&buf, 1, 1, fp_src);
}

i = 0;
// fseek(fp_src, 1, SEEK_CUR);
memset(IP[1],0,sizeof(IP[1]));
fread(&buf, 1, 1, fp_src);
while(buf != '.')
{
IP[1][i] = buf;
i++;
fread(&buf, 1, 1, fp_src);
}

i = 0;
// fseek(fp_src, 1, SEEK_CUR);
memset(IP[2],0,sizeof(IP[2]));
fread(&buf, 1, 1, fp_src);
while(buf != '.')
{
IP[2][i] = buf;
i++;
fread(&buf, 1, 1, fp_src);
}


// read until the '\n'

/* while(buf != '\n')
{
fread(&buf, 1, 1, fp_src);
}*/

}


void Write_one_Line(FILE *fp_des, char IP[][4])
{
char str[4] = "0";
char buf;

strcpy(str, IP[0]);
fwrite(str, strlen(str), 1, fp_des);
buf = '.';
fwrite(&buf, 1, 1, fp_des);

strcpy(str, IP[1]);
fwrite(str, strlen(str), 1, fp_des);
buf = '.';
fwrite(&buf, 1, 1, fp_des);

strcpy(str, IP[2]);
fwrite(str, strlen(str), 1, fp_des);
buf = '.';
fwrite(&buf, 1, 1, fp_des);


strcpy(IP[3], "0");
strcpy(str, IP[3]);
fwrite(str, strlen(str), 1, fp_des);
buf = 0x09;
fwrite(&buf, 1, 1, fp_des);

// 192.168.24.0[tab]

strcpy(str, IP[0]);
fwrite(str, strlen(str), 1, fp_des);
buf = '.';
fwrite(&buf, 1, 1, fp_des);

strcpy(str, IP[1]);
fwrite(str, strlen(str), 1, fp_des);
buf = '.';
fwrite(&buf, 1, 1, fp_des);

strcpy(str, IP[2]);
fwrite(str, strlen(str), 1, fp_des);
buf = '.';
fwrite(&buf, 1, 1, fp_des);


strcpy(IP[3], "255");
strcpy(str, IP[3]);
fwrite(str, strlen(str), 1, fp_des);
buf = '\n';
fwrite(&buf, 1, 1, fp_des);
// 192.168.24.255[enter];
}

int DO_File(char *file_src, char *file_des)
{
FILE *fp_des, *fp_src;

if((fp_src = fopen(file_src, "r")) == NULL)
{
//printf("open %s error !\n", argv[1]);
//MessageBox("Open src_file error !");
return 0;
}

char IP[4][4] = {"0", "0", "0", "0"};
char buf;

/* Read_one_Line(fp_src, IP);
Show_IP(IP);
fclose(fp_src);*/


if((fp_des = fopen(file_des, "wa")) == NULL)
{
//printf("open %s error !\n", argv[2]);
fclose(fp_src);
return 0;
}

/* Write_one_Line(fp_des, IP);
fclose(fp_des);*/

int read_over = 1;

while(read_over)
{
Read_one_Line(fp_src, IP);
/*Show_IP(IP);
printf("\n");*/
Write_one_Line(fp_des, IP);

do
{
read_over = fread(&buf, 1, 1, fp_src);
}
while(buf != '\n' && read_over);
}

fclose(fp_des);

return 1;


}

 

 

// DO_FILE_REAR.h

#include <stdio.h>
#include <stdlib.h>

 

int Read_one_Line(FILE *fp_src, FILE *fp_des)
{
char buf;
long dis;
int flag = 1;

do
{
fread(&buf, 1, 1, fp_src);
if(feof(fp_src))
{
flag = 0;
break;

}

}while(buf != '\n' && flag);


if(flag == 0)
{
dis = 0L;
}
else
{
dis = -3L;
}

 

fseek(fp_src, dis, SEEK_CUR);

while(buf != ' ')
{
fread(&buf, 1, 1, fp_src);

fseek(fp_src, -2L, SEEK_CUR);
}

fseek(fp_src, 2L, SEEK_CUR);

if(flag != 0)
{
while(buf != '\n')
{
fread(&buf, 1, 1, fp_src);
fwrite(&buf, 1, 1, fp_des);

}
}
else
{
do
{
fread(&buf, 1, 1, fp_src);
if(feof(fp_src))
break;
fwrite(&buf, 1, 1, fp_des);
}while(!feof(fp_src));
}

 

return flag;
}


int DO_File_Rear(char *file_src, char *file_des)
{
FILE *fp_src, *fp_des;
char buf;

if((fp_src = fopen(file_src, "r")) == NULL)
{
return 0;
}


rewind(fp_src);


if((fp_des = fopen(file_des, "wa")) == NULL)
{
fclose(fp_src);
return 0;
}
int t = 1;
while(t)
{
t = Read_one_Line(fp_src, fp_des);
}

fclose(fp_src);
fclose(fp_des);
return 1;
}

 

 

设计结果展示:

 

 

posted @ 2013-06-13 00:15  Auris  阅读(70)  评论(0)    收藏  举报