您的位置:首页 > 其它

Hello World

2014-03-03 22:06 260 查看
这是第一篇在CSDN上的日志,我不知道该写些什么。

跟QQ空间不一样,感觉不能灌水。

//头文件
#ifndef_KESHE_
#define_KESHE_
#endif
#pragmaonce
#defineSTUstructstu
#defineUSERstructuser
STU{
intnum;
charname[50];
charsex;
intage;
charplace[50];
chardepartment[50];
charmajar[50];
charclas[50];
STU*next;
STU*pre;
};
USER{
charadmin[100],root[100];
USER*next;
};
#definelogin'a'
#defineexit'b'
#defineadd'a'
#definechange'b'
#definedel'c'
#definefind'd'
#defineoutput'e'
#defineread'f'
#definestatistics'g'
#definedisplay'h'
#definequit'i'
voidAdd();
voidChange();
voidDel();
voidFind();
voidOutput();
voidRead();
voidMaintenance();
intlist();
voidhidden();
voidDisplay();
voidLogin();
voidshow();
voidmenu();
//源文件
#include<stdio.h>
#include<windows.h>
#include"keshe.h"
#include<string.h>
#include<stdlib.h>

STUstatic*head=NULL;
voidAdd()
{
STU*stu1=head,*stu2;
charanswer[100];
if(head==NULL)
{
printf("Doyouwanttocreatanewtable?(Y|N)");
scanf("%s",answer);
if(!strcmp("Y",answer))
{
stu1=stu2=(STU*)malloc(sizeof(STU));
head=stu1;
stu1->pre=head;
stu1->next=NULL;
}
else
{
printf("Backtomenu.");
list();
}
}
while(stu1->next!=NULL)
stu1=stu1->next;
while(1)
{
stu2=(STU*)malloc(sizeof(STU));
printf("Printthenum:");
scanf("%d",&stu2->num);
printf("Printthename:");
scanf("%s",stu2->name);
printf("Printthesex(morw):");
scanf("%s",&stu2->sex);
printf("Printtheage:");
scanf("%d",&stu2->age);
printf("Printtheplace:");
scanf("%s",stu2->place);
printf("Printthedepartment:");
scanf("%s",stu2->department);
printf("Printthemajar:");
scanf("%s",stu2->majar);
printf("Printtheclas:");
scanf("%s",stu2->clas);
stu1->next=stu2;
stu2->pre=stu1;
stu2->next=NULL;
stu1=stu2;
printf("Doyouwanttoaddagain?(Y|N)");
scanf("%s",answer);
if(!strcmp("Y",answer));
else
list();
}
}

voidChange()
{
charanswer[100],t=0;
STU*stu1=head;
printf("pleasescanfwhichnumyouwanttochange:");
scanf("%d",&answer[0]);
while(stu1->num!=answer[0])
{
if(stu1->next!=NULL)
stu1=stu1->next;
else
{
printf("yourscanfiswrong");
list();
}
}
printf("num|name|sex|age|place|department|majar|clas\nwhatdoyouchange?");
scanf("%s",answer);
if(!strcmp("num",answer))
{
while(stu1->num!=answer[0])
{
printf("pleasescanfthenumafterchange:");
scanf("%d",&answer[0]);
if(stu1->next==NULL&&stu1->num!=answer[0])
{
stu1->num=answer[0];
printf("success");
list();
}
else
{
printf("thenumhasbeenhad\n");
system("pause");
list();
}
}
}
elseif(!strcmp("name",answer))
{
printf("pleasescanfthenameafterchange:");
scanf("%s",answer);
strcpy(stu1->name,answer);
printf("success");
list();
}
elseif(!strcmp("sex",answer))
{
printf("pleasescanfthesexafterchange:");
scanf("%s",answer);
stu1->num=answer[0];
printf("success");
list();
}
elseif(!strcmp("age",answer))
{
printf("pleasescanftheageafterchange:");
scanf("%d",&answer[0]);
stu1->num=answer[0];
printf("success");
list();
}
elseif(!strcmp("place",answer))
{
printf("pleasescanftheplaceafterchange:");
scanf("%s",answer);
strcpy(stu1->place,answer);
printf("success");
list();
}
elseif(!strcmp("department",answer))
{
printf("pleasescanfthedepartmentafterchange:");
scanf("%s",answer);
strcpy(stu1->department,answer);
printf("success");
list();
}
elseif(!strcmp("majar",answer))
{
printf("pleasescanfthemajarafterchange:");
scanf("%s",answer);
strcpy(stu1->majar,answer);
printf("success");
list();
}
elseif(!strcmp("clas",answer))
{
printf("pleasescanftheclasafterchange:");
scanf("%s",answer);
strcpy(stu1->clas,answer);
printf("success");
list();
}
else
{
printf("yourscanfiswrong");
list();
}
}

voidDel()
{
charanswer[100];
STU*stu1=head;
printf("whodoyoudel?pleasescanfname:");
scanf("%s",answer);
while(strcmp(stu1->name,answer))
if(stu1->next!=NULL)
stu1=stu1->next;
else
{
printf("yourscanfiswrong");
list();
}
if(stu1->next!=NULL)
stu1->pre->next=stu1->next;
else
stu1->pre->next=NULL;
free(stu1);
printf("success");
list();
}

voidFind()
{
STU*stu1=head;
charanswer[100];
printf("whichnumdoyoufind?");
scanf("%d",&answer[0]);
while(stu1->num!=answer[0])
{
if(stu1->next!=NULL)
stu1=stu1->next;
else
{
printf("yourscanfiswrong");
list();
}
}
printf("num|name|sex|age|place|department|majar|clas\n");
printf("%d,%s,%c,%d,%s,%s,%s,%s\n",
stu1->num,
stu1->name,
stu1->sex,
stu1->age,
stu1->place,
stu1->department,
stu1->majar,
stu1->clas);
system("pause");
list();
}

voidOutput()
{
STU*stu1=head->next;
FILE*fp;
fp=fopen("date.dat","w");
while(stu1!=NULL)
{
fprintf(fp,"%d%s%c%d%s%s%s%s\n",
stu1->num,
stu1->name,
stu1->sex,
stu1->age,
stu1->place,
stu1->department,
stu1->majar,
stu1->clas);
stu1=stu1->next;
}
fclose(fp);
system("pause");
list();
}

voidRead()
{
STU*stu1,*stu2=head;
FILE*fp;
chart;
fp=fopen("date.dat","r");
stu2=(STU*)malloc(sizeof(STU));
head=stu2;
while(!feof(fp))
{
stu1=(STU*)malloc(sizeof(STU));
fscanf(fp,"%d%s%c%d%s%s%s%s\n",
&stu1->num,
stu1->name,
&stu1->sex,
&stu1->age,
stu1->place,
stu1->department,
stu1->majar,
stu1->clas);
stu2->next=stu1;
stu1->pre=stu2;
stu2=stu2->next;
}
stu2->next=NULL;
fclose(fp);
system("pause");
list();
}

voidStatistics()
{
STU*stu1=head;
charanswer[100];
printf("");
}

voidDisplay()
{
STU*stu1=head->next;
printf("num|name|sex|age|place|department|majar|clas\n");
while(stu1!=NULL)
{
printf("%d,%s,%c,%d,%s,%s,%s,%s\n",
stu1->num,
stu1->name,
stu1->sex,
stu1->age,
stu1->place,
stu1->department,
stu1->majar,
stu1->clas);
stu1=stu1->next;
}
system("pause");
list();
}

intlist()
{
charoption=0;
Sleep(1000);
system("cls");
if(head==NULL)
{
printf("——————————————————————————————————————\n");
printf("a.add\n");
printf("f.read\n");
printf("i.quit \n");
printf("——————————————————————————————————————\n");
while(option=getch())
{
if(add==option)
{
Add();
}
elseif(read==option)
{
Read();
}
elseif(quit==option)
{
menu();
}
else
{
printf(" Yourscanfiswrong!");
list();
}
}
}
else
{
printf("——————————————————————————————————————\n");
printf("a.add\n");
printf("b.change\n");
printf("c.del\n");
printf("d.find\n");
if(head->next!=NULL)
printf("e.output\n");
printf("f.read\n");
printf("g.statistics\n");
printf("h.display \n");
printf("i.quit \n");
printf("——————————————————————————————————————\n");
while(option=getch())
{
if(add==option)
{
Add();
}
elseif(change==option)
Change();
elseif(del==option)
{
Del();
}
elseif(find==option)
{
Find();
}
elseif(output==option)
{
Output();
}
elseif(read==option)
{
Read();
}
elseif(statistics==option)
{
Statistics();
}
elseif(quit==option)
{
menu();
}
elseif(display==option)
{
Display();
}
else
{
printf(" Yourscanfiswrong!");
list();
}
}
}
}

voidshow()
{
system("cls");
printf("——————————————————————————————————————\n");
printf("a.login\n");
printf("b.exit\n");
printf("——————————————————————————————————————\n");
}

voidLogin()
{
intn=0;
charusername[100],password[100];
Sleep(1000);
system("cls");
show();
printf("username:");
scanf("%s",&username);
printf("password:");
for(;password
!='\n';n++)
{
password
=getch();
if(password
==13)
{
password
='\0';
printf("\n");
break;
}
printf("*");
}
if(!strcmp("admin",username)&&!strcmp(password,"root"))
{
printf(" Loginsuccessful!");
Sleep(1000);
system("cls");
if(head==NULL)
Add();
else
list();
}
else
{
printf(" UsernameorPasswordiswrong!");
Login();
}
}

voidmenu()
{

charoption=0;
show();
while(option=getch())
{
if(option==login)
{
Login();
}
else
{
printf("Yourinputiswrong");
Sleep(1000);
system("cls");
menu();
}
}
}
voidhidden()//隐藏光标
{
CONSOLE_CURSOR_INFOcci;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cci);
cci.bVisible=0;//赋1为显示,赋0为隐藏
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cci);
}
voidmain()
{
hidden();
while(1)
{
menu();
}
}


/*
不好意思、。。。注释比较少,这是我现在的一个坏习惯。
这是我学C的第一个激动,我终于把C语言的文件那一部分给消化了。

另外,我想每一个学C的人都有疑问吧,因为我们学的时候,敲出来的是在cmd命令框下的console程序。
我当时就一直在想怎么编写出来图形界面的程序,在图书馆找了半天书,终于看到了graphics.H这个头文件。
我一激动,立马把代码敲在了VC++6.0IDE窗口下,一按F5,我的那个伤啊,error:未发现graphics.H。
然后我就在想,是不是能去百度一个头文件放进去呢?
于是#include"graphics.h"
F5
error一排刷下来,当时脸都绿了,打开头文件一看,除了大量的宏定义跟函数声明,啥也没有。这件事也就告一段落。
现在我才明白:不止*.h在起作用。
*.lib跟动态链接库*.dll文件也有很大的作用
提供头文件的商家怕头文件的内容暴露,做成了编译成*.dll动态链接库

最近在看《汇编语言(王爽著)》还有《windows程序设计》。
*/

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: