
用C语言编写一个程序!!!
程序的要求是,通过C语言来读写TXT文本文件,当打开这个C语言编辑好的程序时候,会先验证你的用户ID和口令,如果都正确后,就可以把txt里的内容输出并通过程序直接添加tx...
程序的要求是,通过C语言来读写TXT文本文件,当打开这个C语言编辑好的程序时候,会先验证你的用户ID和口令,如果都正确后,就可以把txt里的内容输出并通过程序直接添加txt的信息,如果口令不正确,则只可以浏览txt内的信息,不可以写入.
===========
请高手帮忙写一个,并把代码粘贴上来,万分感激! 展开
===========
请高手帮忙写一个,并把代码粘贴上来,万分感激! 展开
4个回答
展开全部
我帮你写一个吧。这是个简单的版本。其它的自己加上吧。
#include<stdio.h>
#include<string.h>
#define TrueID 111 //The macro can be changed as you wish.
#define TruePassword 000 //The macro can be changed as you wish.
#define Capacity1 400 //The macro can be changed as you wish.
#define Capacity2 400 //The macro can be changed as you wish.
int main()
{
int i;
char buf[Capacity1];
for(i=0;i<Capacity1;i++)
buf[i]='\0';
char msg[Capacity2];
FILE* fp;
int ID,Password;
printf("Please input your ID:\n");
scanf("%d",&ID);
printf("\n");
printf("Please input your Password:\n");
scanf("%d",&Password);
printf("\n");
if(ID==TrueID && Password==TruePassword)
{
fp = fopen("c:\\file.txt", "r+");
fseek(fp, 0, SEEK_SET);
fread(buf, sizeof(char),500, fp);
printf("%s",buf);
printf("\nInput the text you want to add:\n");
getchar();
gets(msg);
fwrite(msg, strlen(msg)+1, 1, fp);
fclose(fp);
return 0;
}
else
{
fp = fopen("c:\\file.txt", "r");
fseek(fp, 0, SEEK_SET);
fread(buf, sizeof(char),500, fp);
printf("%s",buf);
printf("\n");
fclose(fp);
return 0;
}
}
#include<stdio.h>
#include<string.h>
#define TrueID 111 //The macro can be changed as you wish.
#define TruePassword 000 //The macro can be changed as you wish.
#define Capacity1 400 //The macro can be changed as you wish.
#define Capacity2 400 //The macro can be changed as you wish.
int main()
{
int i;
char buf[Capacity1];
for(i=0;i<Capacity1;i++)
buf[i]='\0';
char msg[Capacity2];
FILE* fp;
int ID,Password;
printf("Please input your ID:\n");
scanf("%d",&ID);
printf("\n");
printf("Please input your Password:\n");
scanf("%d",&Password);
printf("\n");
if(ID==TrueID && Password==TruePassword)
{
fp = fopen("c:\\file.txt", "r+");
fseek(fp, 0, SEEK_SET);
fread(buf, sizeof(char),500, fp);
printf("%s",buf);
printf("\nInput the text you want to add:\n");
getchar();
gets(msg);
fwrite(msg, strlen(msg)+1, 1, fp);
fclose(fp);
return 0;
}
else
{
fp = fopen("c:\\file.txt", "r");
fseek(fp, 0, SEEK_SET);
fread(buf, sizeof(char),500, fp);
printf("%s",buf);
printf("\n");
fclose(fp);
return 0;
}
}
展开全部
有这样的程序啊,人家都那这个程序出书了。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
谁傻啊,不用记事本打开txt
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
记事本吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询