Ⅰ c語言共用體實現設計個人名片,包含姓名,職業,電話
//共用體實例你看看行不
#include<stdio.h>
#include<windows.h>
#include<string.h>
//共用體
unionbusinessCard
{
charname[20];//存儲姓名
charjob[20];//存儲職業
charphoneNum[13];//存儲電話號碼
};
voidmain(void)
{
businessCardcard;
FILE*fp;
if(!(fp=fopen("businessCard.txt","a+")))
{
printf("文件打開失敗 ");
exit(0);
}
else
{
printf(">輸入姓名:");
scanf("%s",card.name);
fprintf(fp,"%s ",card.name);
printf(">輸入職業:");
scanf("%s",card.job);
fprintf(fp,"%s ",card.job);
printf(">輸入電話:");
scanf("%s",card.phoneNum);
fprintf(fp,"%s ",card.phoneNum);
}
fclose(fp);
//從已存儲文件中讀取名片
if(!(fp=fopen("businessCard.txt","r")))
{
printf("文件打開失敗…… ");
exit(0);
}
inti,j;
i=1,j=1;
charbuf[20]="";
while(!feof(fp))
{
if(i==1||i-j*3==1)
{
fgets(card.name,20,fp);
if(strcmp(card.name,buf)!=0)
printf(">姓名:%s",card.name);
}
if(i==2||i-j*3==2)
{
fgets(card.job,20,fp);
printf(">職業:%s",card.job);
}
if(i==3||i-j*3==3)
{
fgets(card.phoneNum,20,fp);
printf(">電話:%s ",card.phoneNum);
strcpy(buf,card.phoneNum);
j++;
}
i++;
}
fclose(fp);
}
Ⅱ 如何用c語言編寫一個程序,輸出一張笑臉
你好
下面是很簡單的顯示程序
沒有使用任何高級語法 樓主應該能看懂
#include <stdio.h>
int main(void)
{
printf(" * * * * *\n"
" * *\n"
" * ^ ^ *\n"
"* *\n"
"* *\n"
"* *\n"
" * ___ *\n"
" * *\n"
" * * * * *\n");
return 0;
}
希望能幫助你哈
Ⅲ 要用c語言設計一個個人通訊錄,要求有步驟的截圖,急急急,求大神幫幫忙啊
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#defineM3
FILE*fp;
charfn[50]={""};
typedefstructmessage{
charname[20];
charaddress[50];
chartelephone[15];
intpostcode;
structmessage*next;
}*LinkList,*NODE;
voidReadData(NODEp){
printf("姓名:");
scanf("%s",p->name);
printf("地址:");
scanf("%s",p->address);
printf("電話號碼:");
scanf("%s",p->telephone);
printf("郵政編碼:");
scanf("%d",&p->postcode);
}
voidShowLine(intn){
inti;
for(i=0;i<n;++i)
printf("*");
printf(" ");
}
voidShowData(NODEp){
printf("%s",p->name);
printf("%s",p->address);
printf("%s",p->telephone);
printf("%d ",p->postcode);
}
voidShowAll(LinkListhead){
NODEp;
if(head==NULL)return;
ShowLine(25);
for(p=head->next;p;p=p->next)
ShowData(p);
ShowLine(25);
}
LinkListCreateList(intn){
NODEhead,p;
inti;
head=p=(LinkList)malloc(sizeof(message));
for(i=0;i<n;++i){
p->next=(LinkList)malloc(sizeof(message));
printf("(%d/%d)的信息: ",i+1,n);
ReadData(p->next);
p=p->next;
}
p->next=NULL;
returnhead;
}
voidAddmember(LinkListhead){//頭插法添加,可用於創建新鏈表
NODEp=(LinkList)malloc(sizeof(message));
ReadData(p);
if(head==NULL){
head->next=p;
p->next=NULL;
}
else{
p->next=head->next;
head->next=p;
}
}
NODESearch(LinkListhead,charname[]){
NODEp;
if(head==NULL)returnNULL;
for(p=head->next;p;p=p->next){
if(strcmp(p->name,name)==0)
ShowData(p);
returnp;
}
returnNULL;
}
voidModifyList(LinkListhead){
NODEp;
charname[20];
printf("被修改人的姓名:");
scanf("%s",name);
p=Search(head,name);
if(p==NULL)printf("查無此人。 ");
else{
ShowData(p);
ReadData(p);
}
}
intErase(LinkListhead,charname[]){//刪除姓名為name的結點
intan;
NODEp,q;
if(head==NULL)return0;
for(p=head;p->next;p=p->next){
if(strcmp(p->next->name,name)==0){
ShowData(p);
printf("1.刪除,0.不刪除:");
scanf("%d",&an);
if(an==1){
q=p->next;
p->next=q->next;
free(q);
return1;
}
elsereturn0;
}
}
return0;
}
voidLoadData(LinkListhead){//傳送文件的內容到內存
NODEp,tmp;
intan;
if(fn[0]=='