200分求一个简单程序

lijixue 2006-04-03 10:20:13
200分一个文件比对程序,两个文本文件全是文档,文档格式为编号16位,品名20位,数量4位
11111111111111111康师付方便面 9999
能比较出两个文档之间的数量差别
文档1是源文件,文档2是新文件,
要求用MS-C做,哪位大侠能做,另开贴给分
...全文
1022 38 打赏 收藏 转发到动态 举报
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
ovol 2006-04-04
  • 打赏
  • 举报
回复
mark
北狐狸 2006-04-04
  • 打赏
  • 举报
回复
mark
sandytian 2006-04-04
  • 打赏
  • 举报
回复
三REN行必有我师,牛比呀.向你学习了
sandytian 2006-04-04
  • 打赏
  • 举报
回复
当个菜鸟真是郁闷看了半天也没看 动 什么东西.
我编了个程序在TC上是正确的,到别的是就不行了,太长了就不写了.
楼主还是要自己多多努力哦,何必死板的要在MS-C上做呢?郁闷!
nipcdll 2006-04-04
  • 打赏
  • 举报
回复
学习
ccccffff 2006-04-04
  • 打赏
  • 举报
回复
up
XPR 2006-04-04
  • 打赏
  • 举报
回复
是不是文本比较器呀?
neve85 2006-04-04
  • 打赏
  • 举报
回复
还没学到那里嘿嘿
lonelyforest 2006-04-04
  • 打赏
  • 举报
回复
又是作业题目吧。
gjianpro 2006-04-04
  • 打赏
  • 举报
回复
lz need patience
lijixue 2006-04-03
  • 打赏
  • 举报
回复
TO:
duduhaha(三人行必有我师)
你看一下你的短信
lijixue 2006-04-03
  • 打赏
  • 举报
回复
#define MAINFILE "main.txt"
#define OUTPUTFILE "output.txt"

#define F4 -119

//------Global value Zone-------------------------------------------------------------------------------

int g_nSubM,g_nSubFunC,g_nSubFunA,g_nPos,g_nFunAGo,g_nRet;
long g_lnQty;

char szFile[20],szTotal[10],szRecord[60];
char szBarcode[20],szName[40],szPrice[10];
char szInputQty[5],szInputLocation[5];



//--各种操作成功后的发音

void OkBeep()
{
_beep(2,2);
_beep(4,2);
_beep(6,2);
_beep(8,2);
}

//------void ErrBeep()----------------------------------------------------------------------------------
//--各种操作失败后的发音

void ErrBeep()
{
_beep(5,1);
_beep(5,1);
_beep(5,1);
_beep(5,1);
}

//------void CreateBeep()-------------------------------------------------------------------------------
//--创建文档成功后的发音

void CreateBeep()
{
_beep(4,1);
}

//------void delay()------------------------------------------------------------------------------------
//--延迟

void delay(int d)
{
long i,tt, limit;

limit = d * 1000;

for(i=0L; i<limit; i++)
for(tt=5000; tt<0; tt--);
}

//------void ShowMsg()----------------------------------------------------------------------------------
//--显示提示信息

void ShowMsg(char *szShow,int nFont,int nRow,int nCell,int nSound)
{
_set_font(nFont);
_enable_screen_scroll(0); _enable_cursor(0);

_set_cursor(nRow,nCell); printf("%s",szShow);
if (nSound==1)
OkBeep();
else if(nSound==0)
ErrBeep();
delay(526);
}

//---------------------------------------------------------------------------------

int WndMain()
{
char cPadKey;

_set_font(0);
_enable_cursor(0); _enable_screen_scroll(0);
// _set_cursor(0,4); printf("%c7r[盘点程序%c0r[",27,27);
_set_cursor(0,0); printf("1.扫描输入");
_set_cursor(1,0); printf("2.传输");
_set_cursor(2,0); printf("3.设定");


while(1)
{

cPadKey=_getc_ne();
if(cPadKey>='1'&&cPadKey<='3')
return (int)(cPadKey-0x30);
else if(cPadKey==F4)
return;
else
ErrBeep();
}
}

//-----------------------------------------------------------------------------

int WndSet()
{
char cPadKey;

_set_font(0);
_enable_cursor(0); _enable_screen_scroll(0);

_set_cursor(0,6); printf("%c7r[设定%c0r[",27,27);
_set_cursor(1,3); printf("1.数量设定");
_set_cursor(2,3); printf("2.储位设定");
while(1)
{
cPadKey=_getc_ne();
if(cPadKey=='1'||cPadKey=='2')
return (int)(cPadKey-0x30);
else if(cPadKey==F4)
return F4;
else
ErrBeep();
}
}

//-------------------------------------------------------------

int WndSubSet(int nRet)
{
char cPadKey;

_set_font(0);
_enable_cursor(0); _enable_screen_scroll(0);

_set_cursor(0,1);
if(nRet==1)
printf("%c7r[是否输入[数量]%c0r[",27,27);
else
printf("%c7r[是否输入[储位]%c0r[",27,27);
_set_cursor(1,6); printf("1.是");
_set_cursor(2,6); printf("2.否");

while(1)
{
cPadKey=_getc_ne();
if(cPadKey=='1'||cPadKey=='2')
return (int)(cPadKey-0x30);
else if(cPadKey==F4)
return;
else
ErrBeep();
}
}

//--------------------------------------------------------------

int AllDigit(char *str)
{
int i,nLen;

nLen=strlen(str);
for (i=0;i<nLen;i++)
{
if (str[i]<'0' || str[i]>'9')
return (0);
}
return (1);
}

//---------------------------------------------------------------

void WndInputBarcode()
{
_set_font(0);
_enable_cursor(1); _enable_screen_scroll(0);

_set_cursor(1,0); printf("条码:");
_set_cursor(2,0); printf("________________");
}
//---------------------------------------------------------------

void WndShow()
{
_set_font(0);
_enable_cursor(0); _enable_screen_scroll(0);

_set_cursor(0,0); printf("品牌:");
_set_cursor(2,4); printf("地点:");
}

//----------------------------------------------------------------

void WndNotExit()
{
_set_font(0);
_enable_cursor(0); _enable_screen_scroll(0);

ErrBeep();
_set_cursor(1,2); printf("此条码不存在!");
_set_cursor(2,2); printf("按任一键继续");
}

//-----------------------------------------------------------------

void WndInputQty()
{
_set_font(0);
_enable_cursor(0); _enable_screen_scroll(0);

_set_cursor(0,0); printf("上次数量:");
_set_cursor(1,0); printf("数量:");
if(atoi(szInputLocation)==1)
{
_set_cursor(2,0); printf("储位:");
}
}

//---------------------------------------------------------------

这是主程序
lijixue 2006-04-03
  • 打赏
  • 举报
回复
#define MAINFILE "main.txt"
#define OUTPUTFILE "output.txt"
这是定义的文件
char szFile[20],szTotal[10],szRecord[60];
这是定义的数据
风里有梦 2006-04-03
  • 打赏
  • 举报
回复
樓主你這個文件格式定義有問題,為什麼不先設定:

1、文件頭
2、文件內容

可參考DBF文件格式。你這個自定義數據最大的錯誤就是不應該以換行的方式來決定下一條記錄,應該是連續的,這樣的話,就可讀入到結構里面處理了,非常方便:

如下結構:


typedef struct {
char code[16]; // 編號
char name[20]; // 品名
int qty; // 數量
} ITEM_DATA, *PITEM_DATA;

lijixue 2006-04-03
  • 打赏
  • 举报
回复
_star()
{
_enable_cursor(1);
_clear_screen();
_set_font(0);
_set_cursor(0,0); printf("1、登陆 2、输入");
_set_cursor(1,0); printf("3、下载 4、上传");
_set_cursor(2,0); printf("5、核对 6、浏览");
_set_cursor(3,1); printf("7、设定密码");
//_set_cursor(4,10); _getc_ne();//
}

这是主程序

_CheckBarcode()
{
FILE *fp;
int nPos,nLen,nRet;

nRet=1;
g_nSubFunA=1;
nLen=strlen(_Barcode);
if(nLen==13||nLen==16)
{
if((fp=fopen(MAINFILE,"ab+"))!=NULL)
{
fclose(fp);
memset(szBarcode,0,sizeof(szBarcode));
sprintf(szBarcode,"%s",_Barcode);
memset(szTemp,0,sizeof(szTemp));
nPos=SearchFieldGr(MAINFILE,szBarcode,1,1,',',1,FORWARD||FULLMATCH,szTemp);
if(nPos!=0)
{
memset(szName,0,sizeof(szName));
strncpy(szName,szTemp+16,30);
memset(szPrice,0,sizeof(szPrice));
strncpy(szPrice,szTemp+46,6);
WndShow();
_set_cursor(0,5); printf("%-30s",szName);
_set_cursor(2,9); printf("%-6s",szPrice);
_set_cursor(3,2); printf("按任一键继续");
_getc_ne();
memset(szInputQty,0,sizeof(szInputQty));
strcpy(szInputQty,ReadRecord("qty.txt",1,0));
memset(szInputLocation,0,sizeof(szInputLocation));
strcpy(szInputLocation,ReadRecord("location.txt",1,0));
WndInputQty();

memset(szTotal,0,sizeof(szTotal));
g_nPos=SearchFieldGr(OUTPUTFILE,szBarcode,1,1,',',1,FORWARD||FULLMATCH,szTemp);
if(g_nPos!=0)
{
strncpy(szTotal,szTemp+16,6);
g_lnQty=atol(szTotal);
}
else
g_lnQty=0L;

_set_cursor(0,9); printf("%-6ld",g_lnQty);

_enable_cursor(1);
if(atoi(szInputQty)==0)
{
_set_cursor(1,5); printf("1");
}
else
{
_set_cursor(1,5); printf("0");
}
if(atoi(szInputQty)==0&&(atoi(szInputLocation))==0)
{
_enable_cursor(0);
_set_cursor(3,3); printf("任一键保存");
_getc_ne();
}
}
else
nRet=0;
}
}
else
nRet=0;
if(nRet==0)
{
g_nSubFunA=0;
WndNotExit();
_getc_ne();
}
}
这是输入程序
duduhaha 2006-04-03
  • 打赏
  • 举报
回复
做的更好的程序.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct result
{
char name[50];
int diff;
};

int countHanZi(char a[]);

int main(void)
{
char a[200];
char b[200];
struct result result[50];
FILE *fp1,*fp2;
int length1;
int length2;
int temp1,temp2;
int i = 0;
int k;

fp1 = fopen("1.txt","r");
if(fp1 == NULL)
{
printf("error1\n");
exit(-1);
}
fp2 = fopen("2.txt","r");
if(fp2 == NULL)
{
printf("error1\n");
exit(-1);
}

while(1)
{
if(fgets(a,100,fp1) == NULL)
break;
if(fgets(b,100,fp2) == NULL)
break;
length1 = strlen(a);
length2 = strlen(b);
if(a[length1 - 1] == '\n')
a[length1 - 1] = '\0';
if(b[length2 - 1] == '\n')
b[length2 - 1] = '\0';
k = countHanZi(a + 16);
memset(result[i].name,0,50);
memmove(result[i].name,a + 16,2 * k);


temp1 = atoi(a + length1 - 5);
temp2 = atoi(b + length2 - 5);

result[i].diff = temp1 - temp2;
memset(a,0,100);
memset(b,0,100);
i++;
}

printf("The difference of each product is:\n");

int j;
for(j = 0; j < i; j++)
printf("%s:%d\n",result[j].name,result[j].diff);
fclose(fp1);
fclose(fp2);

return 0;
}

int countHanZi(char a[])
{
int i = 0;
char *p = a;

while(!isspace(*p))
{
p = p + 2;
i++;
}

return i ;
}
1.txt:
11111111111111111康师付方便面 9999
22222222222222222统一冰红茶 8888
2.txt;
11111111111111111康师付方便面 9980
22222222222222222统一冰红茶 8872

顺便说一下,楼主你给的测试文件里面有17个1......
我仔细数了一下,给你改了过来.






lijixue 2006-04-03
  • 打赏
  • 举报
回复
晕哦,我就这个做不好了
benlei999 2006-04-03
  • 打赏
  • 举报
回复
如果用纯C,那就自己实现一个类似的map吧
benlei999 2006-04-03
  • 打赏
  • 举报
回复
用STL
把两个文件的记录分别读进两个Map(编号,数量),
然后比较,输出
lijixue 2006-04-03
  • 打赏
  • 举报
回复
to :duduhaha(三人行必有我师)
我运行的时候他说
?ERROR:Macro redefinition of mainfile
TO:baofeng(~天才白痴~)
不一定,要按编号来
加载更多回复(18)

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧