当前位置:首页 » 编程语言 » c语言编写卡路里代码
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言编写卡路里代码

发布时间: 2022-08-03 18:45:39

Ⅰ 一个简单的c++程序 输入糖果的名称重量卡路里 然后输出

汗,刚才我看没图来着,格式控制你自己尝试下吧,就该加\t的加,该加\n就加\n,呵呵...下次如果能有分数奖励就更好了,哈哈
#include<iostream>
#include<string>
using
namespace
std;
void
main()
{
string
name[10];
string
s;
char
c;
double
m,k;
c,m,k
=0;
while
(c!='n')
{
cout
<<
"请输入糖果名称"<<endl;
cin
>>
s;
cout
<<
"请输入糖果重量(单位:千克)"<<endl;
cin
>>
m;
cout
<<
"请输入糖果卡路里(单位:焦耳)"<<endl;
cin
>>
k;
cout
<<
"
糖果:
"<<
s
<<endl;
cout
<<
"
重量:
"<<
m
<<"千克"<<endl;
cout
<<
"
卡路里:"<<
k
<<"焦耳"<<endl;
cout
<<
"输入n退出,输入任意数继续"<<endl;
cin>>c;
}
}

Ⅱ 用c语言编写程序:输入体重和身高,输出体重指数BMI

例子如下:

知识扩展:

BMI指数(即身体质量指数,简称体质指数又称体重,英文为Body Mass Index,简称BMI),是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。主要用于统计用途,当我们需要比较及分析一个人的体重对于不同高度的人所带来的健康影响时,BMI值是一个中立而可靠的指标。

BMI值原来的设计是一个用于公众健康研究的统计工具。当我们需要知道肥胖是否对某一疾病的致病原因时,我们可以把病人的身高及体重换算成BMI值,再找出其数值及病发率是否有线性关联。不过,随着科技进步,现时BMI值只是一个参考值。要真正量度病人是否肥胖,还需要利用微电力量度病人的阻抗,以推断病者的脂肪厚度。因此,BMI的角色也慢慢改变,从医学上的用途,变为一般大众的纤体指标。

Ⅲ C语言编程问题

#include"stdio.h"

typedefstruct
{
char*name;
doubleweight;
intcalorie;
}CandyBar;

voidShow_CandyBar(CandyBar*Candies)
{
intMode=0;
printf("是否显示默认值? ");
printf("输入0显示默认值,输入1或其他数字自定义输入 ");
scanf_s("%d",&Mode);

if(Mode)
{
printf("请输入糖果名:");
//这里写scanf字符串赋值糖果名
printf("请输入糖果质量:");
scanf_s("%lf",&Candies->weight);
printf("请输入糖果卡路里值:");
scanf_s("%d",&Candies->calorie);
}

printf("name:%s ",Candies->name);
printf("weight:%lf ",Candies->weight);
printf("calorie:%d ",Candies->calorie);
}

intmain()
{
CandyBarCandies;

Candies.name="MillenniumMunch";
Candies.weight=2.85;
Candies.calorie=350;

Show_CandyBar(&Candies);
return0;
}

Ⅳ C语言编写代码

代码:

#include

int main()

{

printf("Hello World. ");

return 0;

}



(4)c语言编写卡路里代码扩展阅读:

代码解析:

1.其中第一行的#include ,这行代码是编译预处理指令,用来提供输入输出函数的声明和宏的定义,全局量的定义这些信息。stdio.h是系统提供的一个文件名,stdio是为standard input & output的缩写,意为标准输入输出,文件后缀.h的意思是头文件(header file),因为这些文件都是放在程序各文件模块的开头的。总的来说,输入输出函数的相关信息已事先放在stdio.h文件中,然后,要用#include指令把这些信息调入供使用。

2.void main(){},main是主函数的函数名,表示这是一个主函数,每一个C源程序都必须有且只能有一个主函数。

3.函数调用语句,即调用printf("Hello World ");语句 ,printf函数的功能是把要输出的内容送到显示器去显示,即打印输出Hello World到windows 控制台下,其中 为转义字符,具有转行的功能。

4.printf函数是一个由系统定义的标准函数,可在程序中直接调用。

Ⅳ 用C语言编写一段代码

#include<stdio.h>
char a[1024];
char b[1024];
void main()
{
char a[1024];
char b[1024];
char *p=a,*q=b;
printf("Please input text:\n");
gets(a);
while(*p)
{
switch(*p)
{
case 'a':
p++;
switch(*p)
{
case 'n':
p++;
switch(*p)
{
case 'd':p++;break;
default:*q++=*p++;break;
}
break;
default:*q++=*p++;break;
}
break;
case 't':
*q++=*p++;
switch(*p)
{
case 'e':
*q++=*p++;
switch(*p)
{
case 'x':
*q++=*p++;
switch(*p)
{
case 't':q-=3;p++;break;
default:*q++=*p++;break;
}
break;
default:*q++=*p++;break;
}
break;
default:*q++=*p++;break;
}
break;
default:*q++=*p++;break;
}
}
*q='\0';
printf("..............\n");
printf("%s\n", b);
getch();
}

Ⅵ 求一个用C语言编写的小游戏代码

#include <graphics.h>
#include <conio.h>
#include <time.h>

/////////////////////////////////////////////
// 定义常量、枚举量、结构体、全局变量
/////////////////////////////////////////////

#define WIDTH 10 // 游戏区宽度
#define HEIGHT 22 // 游戏区高度
#define SIZE 20 // 每个游戏区单位的实际像素

// 定义操作类型
enum CMD
{
CMD_ROTATE, // 方块旋转
CMD_LEFT, CMD_RIGHT, CMD_DOWN, // 方块左、右、下移动
CMD_SINK, // 方块沉底
CMD_QUIT // 退出游戏
};

// 定义绘制方块的方法
enum DRAW
{
SHOW, // 显示方块
HIDE, // 隐藏方块
FIX // 固定方块
};

// 定义七种俄罗斯方块
struct BLOCK
{
WORD dir[4]; // 方块的四个旋转状态
COLORREF color; // 方块的颜色
} g_Blocks[7] = { {0x0F00, 0x4444, 0x0F00, 0x4444, RED}, // I
{0x0660, 0x0660, 0x0660, 0x0660, BLUE}, // 口
{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA}, // L
{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW}, // 反L
{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN}, // Z
{0x0360, 0x4620, 0x0360, 0x4620, GREEN}, // 反Z
{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}}; // T

// 定义当前方块、下一个方块的信息
struct BLOCKINFO
{
byte id; // 方块 ID
char x, y; // 方块在游戏区中的坐标
byte dir:2; // 方向
} g_CurBlock, g_NextBlock;

// 定义游戏区
BYTE g_World[WIDTH][HEIGHT] = {0};

/////////////////////////////////////////////
// 函数声明
/////////////////////////////////////////////

void Init(); // 初始化游戏
void Quit(); // 退出游戏
void NewGame(); // 开始新游戏
void GameOver(); // 结束游戏
CMD GetCmd(); // 获取控制命令
void DispatchCmd(CMD _cmd); // 分发控制命令
void NewBlock(); // 生成新的方块
bool CheckBlock(BLOCKINFO _block); // 检测指定方块是否可以放下
void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW); // 画方块
void OnRotate(); // 旋转方块
void OnLeft(); // 左移方块
void OnRight(); // 右移方块
void OnDown(); // 下移方块
void OnSink(); // 沉底方块

/////////////////////////////////////////////
// 函数定义
/////////////////////////////////////////////

// 主函数
void main()
{
Init();

CMD c;
while(true)
{
c = GetCmd();
DispatchCmd(c);

// 按退出时,显示对话框咨询用户是否退出
if (c == CMD_QUIT)
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("您要退出游戏吗?"), _T("提醒"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
Quit();
}
}
}

// 初始化游戏
void Init()
{
initgraph(640, 480);
srand((unsigned)time(NULL));

// 显示操作说明
setfont(14, 0, _T("宋体"));
outtextxy(20, 330, _T("操作说明"));
outtextxy(20, 350, _T("上:旋转"));
outtextxy(20, 370, _T("左:左移"));
outtextxy(20, 390, _T("右:右移"));
outtextxy(20, 410, _T("下:下移"));
outtextxy(20, 430, _T("空格:沉底"));
outtextxy(20, 450, _T("ESC:退出"));

// 设置坐标原点
setorigin(220, 20);

// 绘制游戏区边界
rectangle(-1, -1, WIDTH * SIZE, HEIGHT * SIZE);
rectangle((WIDTH + 1) * SIZE - 1, -1, (WIDTH + 5) * SIZE, 4 * SIZE);

// 开始新游戏
NewGame();
}

// 退出游戏
void Quit()
{
closegraph();
exit(0);
}

// 开始新游戏
void NewGame()
{
// 清空游戏区
setfillstyle(BLACK);
bar(0, 0, WIDTH * SIZE - 1, HEIGHT * SIZE - 1);
ZeroMemory(g_World, WIDTH * HEIGHT);

// 生成下一个方块
g_NextBlock.id = rand() % 7;
g_NextBlock.dir = rand() % 4;
g_NextBlock.x = WIDTH + 1;
g_NextBlock.y = HEIGHT - 1;

// 获取新方块
NewBlock();
}

// 结束游戏
void GameOver()
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("游戏结束。\n您想重新来一局吗?"), _T("游戏结束"), MB_YESNO | MB_ICONQUESTION) == IDYES)
NewGame();
else
Quit();
}

// 获取控制命令
DWORD m_oldtime;
CMD GetCmd()
{
// 获取控制值
while(true)
{
// 如果超时,自动下落一格
DWORD newtime = GetTickCount();
if (newtime - m_oldtime >= 500)
{
m_oldtime = newtime;
return CMD_DOWN;
}

// 如果有按键,返回按键对应的功能
if (kbhit())
{
switch(getch())
{
case 'w':
case 'W': return CMD_ROTATE;
case 'a':
case 'A': return CMD_LEFT;
case 'd':
case 'D': return CMD_RIGHT;
case 's':
case 'S': return CMD_DOWN;
case 27: return CMD_QUIT;
case ' ': return CMD_SINK;
case 0:
case 0xE0:
switch(getch())
{
case 72: return CMD_ROTATE;
case 75: return CMD_LEFT;
case 77: return CMD_RIGHT;
case 80: return CMD_DOWN;
}
}
}

// 延时 (降低 CPU 占用率)
Sleep(20);
}
}

// 分发控制命令
void DispatchCmd(CMD _cmd)
{
switch(_cmd)
{
case CMD_ROTATE: OnRotate(); break;
case CMD_LEFT: OnLeft(); break;
case CMD_RIGHT: OnRight(); break;
case CMD_DOWN: OnDown(); break;
case CMD_SINK: OnSink(); break;
case CMD_QUIT: break;
}
}

// 生成新的方块
void NewBlock()
{
g_CurBlock.id = g_NextBlock.id, g_NextBlock.id = rand() % 7;
g_CurBlock.dir = g_NextBlock.dir, g_NextBlock.dir = rand() % 4;
g_CurBlock.x = (WIDTH - 4) / 2;
g_CurBlock.y = HEIGHT + 2;

// 下移新方块直到有局部显示
WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
while((c & 0xF) == 0)
{
g_CurBlock.y--;
c >>= 4;
}

// 绘制新方块
DrawBlock(g_CurBlock);

// 绘制下一个方块
setfillstyle(BLACK);
bar((WIDTH + 1) * SIZE, 0, (WIDTH + 5) * SIZE - 1, 4 * SIZE - 1);
DrawBlock(g_NextBlock);

// 设置计时器,用于判断自动下落
m_oldtime = GetTickCount();
}

// 画方块
void DrawBlock(BLOCKINFO _block, DRAW _draw)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

int color = BLACK;
switch(_draw)
{
case SHOW: color = g_Blocks[_block.id].color; break;
case HIDE: color = BLACK; break;
case FIX: color = g_Blocks[_block.id].color / 3; break;
}
setfillstyle(color);

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if (y < HEIGHT)
{
if (_draw != HIDE)
bar3d(x * SIZE + 2, (HEIGHT - y - 1) * SIZE + 2, (x + 1) * SIZE - 4, (HEIGHT - y) * SIZE - 4, 3, true);
else
bar(x * SIZE, (HEIGHT - y - 1) * SIZE, (x + 1) * SIZE - 1, (HEIGHT - y) * SIZE - 1);
}
}
b <<= 1;
}
}

// 检测指定方块是否可以放下
bool CheckBlock(BLOCKINFO _block)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if ((x < 0) || (x >= WIDTH) || (y < 0))
return false;

if ((y < HEIGHT) && (g_World[x][y]))
return false;
}
b <<= 1;
}

return true;
}

// 旋转方块
void OnRotate()
{
// 获取可以旋转的 x 偏移量
int dx;
BLOCKINFO tmp = g_CurBlock;
tmp.dir++; if (CheckBlock(tmp)) { dx = 0; goto rotate; }
tmp.x = g_CurBlock.x - 1; if (CheckBlock(tmp)) { dx = -1; goto rotate; }
tmp.x = g_CurBlock.x + 1; if (CheckBlock(tmp)) { dx = 1; goto rotate; }
tmp.x = g_CurBlock.x - 2; if (CheckBlock(tmp)) { dx = -2; goto rotate; }
tmp.x = g_CurBlock.x + 2; if (CheckBlock(tmp)) { dx = 2; goto rotate; }
return;

rotate:
// 旋转
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.dir++;
g_CurBlock.x += dx;
DrawBlock(g_CurBlock);
}

// 左移方块
void OnLeft()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x--;
DrawBlock(g_CurBlock);
}
}

// 右移方块
void OnRight()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x++;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x++;
DrawBlock(g_CurBlock);
}
}

// 下移方块
void OnDown()
{
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.y--;
DrawBlock(g_CurBlock);
}
else
OnSink(); // 不可下移时,执行“沉底方块”操作
}

// 沉底方块
void OnSink()
{
int i, x, y;

// 连续下移方块
DrawBlock(g_CurBlock, HIDE);
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
while (CheckBlock(tmp))
{
g_CurBlock.y--;
tmp.y--;
}
DrawBlock(g_CurBlock, FIX);

// 固定方块在游戏区
WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
for(i = 0; i < 16; i++)
{
if (b & 0x8000)
{
if (g_CurBlock.y - i / 4 >= HEIGHT)
{ // 如果方块的固定位置超出高度,结束游戏
GameOver();
return;
}
else
g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;
}

b <<= 1;
}

// 检查是否需要消掉行,并标记
int row[4] = {0};
bool bRow = false;
for(y = g_CurBlock.y; y >= max(g_CurBlock.y - 3, 0); y--)
{
i = 0;
for(x = 0; x < WIDTH; x++)
if (g_World[x][y] == 1)
i++;
if (i == WIDTH)
{
bRow = true;
row[g_CurBlock.y - y] = 1;
setfillstyle(WHITE, DIAGCROSS2_FILL);
bar(0, (HEIGHT - y - 1) * SIZE + SIZE / 2 - 2, WIDTH * SIZE - 1, (HEIGHT - y - 1) * SIZE + SIZE / 2 + 2);
}
}

if (bRow)
{
// 延时 200 毫秒
Sleep(200);

// 擦掉刚才标记的行
IMAGE img;
for(i = 0; i < 4; i++)
{
if (row[i])
{
for(y = g_CurBlock.y - i + 1; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
g_World[x][y - 1] = g_World[x][y];
g_World[x][y] = 0;
}

getimage(&img, 0, 0, WIDTH * SIZE, (HEIGHT - (g_CurBlock.y - i + 1)) * SIZE);
putimage(0, SIZE, &img);
}
}
}

// 产生新方块
NewBlock();
}

Ⅶ 用C语言编写一个有关顺序表的程序代码

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

#define Size 50

//定义顺序表结构体类型

typedef struct Table{
int*head;//顺序表头指针,为整型
int length;//顺序表中元素个数
int size; //顺序表的长度
}Table;

//创建顺序表
Table CreateTable(){
Table T;
if(!(T.head=(int*)malloc(Size*sizeof(int)))){
printf("内存分配错误!\n");
exit(0);
}

T.size=Size;
T.length=0;
return T;
}

//增加
void Insert(Table T,int set,int values)//set为插入的位置,values为值
{
//首先判断插入位置是否正确
if(set<0||set>T.length){
printf("插入位置不正确!\n");
reutrn;
}

//判断是否有足够的内存空间存储增加的数
if(T.length==T.size){
if(!(T.head=(int*)realloc(T.head,(T.size+10)*sizeof(int)))){
printf("内存分配错误!\n");
exit(0);
}
T.size+=10;
}

//插入数据
for(int i=s.length;i>set;i--)
T.head[i]=T.head[i-1];

T.head[set]=values;
T.length++;
}

//删除
void Delete(Tabel T,int set)
{
if(set<0||set>=T.length)
{
printf("删除数的位置不争确,删除失败!\n");
return;
}

//输出数据
for(int i=set;i<s.length;i++)
T.head[i]=T.head[i+1];
T.length--;
}

//查找
int Search(Tabel T,int value)
{
for(int i=0;i<T.length;i++)
if(T.head[i]==value)
return i;
return -1;
}

Ⅷ C语言编写的记事本源代码

#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#define NULL 0
#define MAX 100

typedef struct lnode{

char date[MAX]; //存放数据
struct lnode * prior ; //前驱
struct lnode * next ; //后继
int number ; //记录一个节点的字符数!如果是头节点就记录他的节点个数
int quese ; //记录节点在链表中的位置

}lnodetype;

lnodetype * l ; //设置两个全局变量,分别是头节点指针和尾节点指针
lnodetype * end ;

//**********这个函数是用来初始化的**********//
int iniatelist (lnodetype ** l , lnodetype ** end)
{

(*l) = (lnodetype *)malloc (sizeof (lnodetype) ) ;
if ( (*l) == NULL )
{

printf ("没有只够的内存空间!程序即将退出!");
return 0 ;

}

(*l)->prior =(*l)->next = NULL ; //这是双链表
(*l)->number = (*l)->quese = 0;
(*end) = (*l) ;

printf ("程序初始化完毕!");
return 0;

}

//**********这个函数是用来建立节点,并且插入元素的**********//
int link(lnodetype ** l, lnodetype ** end)
{

lnodetype *s ;
s = (lnodetype *)malloc ( sizeof (lnodetype) ) ;
if ( s == NULL ){

printf ("内存空间不够,程序即将退出!") ;
return 0 ;

}

(*end)->next = s ;
s->prior = (*end) ;
(*end) = (*end)->next ;
(*l)->number++ ; //增加一个节点,头节点的number就加1
s->quese = (*l)->number ; //这个是记录节点在链表中的位置

printf ("%d行", s->quese ) ; //这个是节点在整个链表中的位置
gets(s->date) ;
s -> number = strlen(s->date) ;
return 0 ;

}

//**********这个是打印链表的函数**********//
int prin (lnodetype ** l, lnodetype ** end)
{

lnodetype * p ;
int i ;
int j = 0;
int couter = (*l)->number ;
p = (*l)->next ;

for (i=0; i < couter; i++){

printf ( "%d行" , i+1 ) ;
j = 0;
while ( ( p->date[j]>='a' && p->date[j]<='z') ||
(p->date[j]>='A' && p->date[j]<='z') ||
p->date[j]>='0' && p->date[j]<='9')
{

printf ( "%c" , p->date[j] ) ;
j++ ;

}
printf ("n") ;
p = p->next ;

}

return 0 ;

}

//*********这个查找和编辑相应行的函数**********//
int search (lnodetype ** l, lnodetype ** end )
{

int number ;
scanf ("%d" , &number) ;
int i ;
lnodetype * p ;
p = (*l)->next ;

for ( i=0; i<number-1; i++ )
p = p->next ;

printf ("%d行" , number ) ;
gets (p->date) ;
return 0 ;

}

//**********这个是在文本文件里搜索字符串的函数**********//
int searchstr(lnodetype ** l , lnodetype ** end)
{

char ptr[100] ;
int arrycouter ;
int mystrcmp( char *, char * , int ) ;

printf ( "ok!现在输入你查找的字符串!" ) ;
scanf ( "%s" , ptr ) ;
arrycouter = strlen (ptr) ;
lnodetype * s ;
s = (*l)->next ;
char * p ;

int i = 1 ;
int couter = 0 ;
int number = (*l)->number ;
p = (char *)s->date ;

while ( i && number ){

// i=1是,证明没有找到,向第二个节点继续寻找

while ( i && ( ( (*p >= 'a') && (*p <= 'z') ) || ( (*p >= 'A') && (*p <= 'Z') ) ) ){

i = mystrcmp ( p , ptr , arrycouter );

if ( i == 1 ){

printf ("字符串已经在第%d行,第%d个字符开始,",s->quese, couter+1 );
i = 0 ;
}
else
{
p++ ;
couter++;
i = 1 ;
}

}

s = s->next ;
p = (char *)s->date ;
number -- ;

}

if ( i == 1 )
printf ("字符串在本文档中不存在!");
return 0 ;

}

//**********(1)这个函数是用来实现退出不保存功能的**********//
int exitunsave(lnodetype ** l, lnodetype ** end)
{

lnodetype * s ;
while( (*l) != (*end) ){ //如果不保存的话,最好是把节点的空间都释放,节省空间

s = (*end) ;
(*end) = (*end)->prior ;
free( s ) ;

}

return 0 ;

}

//**********(2)这个函数是用来实现退出但保存功能的**********//
int quitandsave( lnodetype ** l , lnodetype ** end )
{

FILE * fp ;
char ch ;
char filename[20] ;
lnodetype * p;
int i ;
int j ;
int couter = (*l)->number ;

p = (*l)->next ;

printf ("请输入文件名:") ;
scanf ("%s" , filename ) ;

if ( (fp = fopen( filename , "w" )) == NULL ){

printf ("文件不能打开!n");
return 0 ;

}

for ( i=0; i<couter; i++ ){ //有几个节点就进行多少次的存贮

ch = p->date[0] ;
j = 1 ;

while (ch != '\0'){

fputc (ch , fp) ;
ch = p->date[j] ;
j++ ;

}

p = p->next ;
fputc ( '#' , fp ) ; //注意在每个节点的后面加上结束的符号

}

fputc ( '@' , fp ) ; //整个文件关闭的标志
fclose ( fp ) ; //注意关闭文件,
return 0 ;

}
//**********由于库函数比较字符串提供的功能不满足要求,故自己写了一个**********/
int mystrcmp( char * p ,char * sour ,int number )
{

while ( number && (*p) == (*sour) &&
( ( (*p >= 'a') && (*p <= 'z') ) || ( (*p >= 'A') && (*p <= 'Z') ) )){

p++ ;
sour++ ;
number-- ;

}

if ( number == 0 )
return 1 ;
else
return 0 ;

}
//**********这个函数是用来实现统计字符串功能的**********//
int coutword(lnodetype ** l , lnodetype ** end)
{ //考虑到只统计一行的单词没有意义,故统计整个文本

int yes = 1 ; //这个是进入单词的标志
int no = 0 ; //在单词外面的时候的标志
int i , j ,inaword ,count = 0 ;
inaword = no ;
lnodetype * s = (*l)->next ;

for (j=0; j<(*l)->number; j++){

for ( i=0; (s->date[i]>='a' && s->date[i]<='z') ||
(s->date[i]>='A' && s->date[i]<='z') ||
(s->date[i]>='0' && s->date[i]<='9' ) ||
(s->date[i]==' '); i++ )
{

if ( s->date[i] == ' ' )
inaword = no ;
else
if ( inaword == no )
{
inaword = yes ;
count++ ; //计算单词
}

}

s = s->next ;
inaword = 0 ; //注意这里,把标志置为0了!

}

printf ( "n文本一共有 %d 行" , (*l)->number ) ;
printf ("n此文本一共有 %d 个单词!" , count ) ;

return count ;

}
//**********这个函数是用来实现计算文本行数功能的**********//
int linecouter(lnodetype ** l , lnodetype ** end )
{

int couter ;
couter = (*l)->number ;
return couter ;

}

//**********这个函数是整和一上所有功能的菜单函数**********//
int editmenu(lnodetype ** l , lnodetype ** end )
{

char choice ;
char * p = "cls" ;
int i = 1 ; //这两个变量是用来控制循环的
int j= 1 ;
system (p) ;
prin (&(*l) , &(*end)) ;

while (j){

printf ("*********************************** e: 编辑相应行 *************************************n") ;
printf ("*********************************** s: 搜索字符串 *************************************n") ;
printf ("*********************************** t: 统计单词个数 ***********************************n") ;
printf ("*********************************** q: 退出编辑 ***************************************n") ;

scanf("%c",&choice);
scanf("%c" , &choice) ; //????莫名其妙的问题,非要两个请求输入语句才肯停下来!
switch (choice)
{
case 'e' : {
i = 1 ;
while (i)
{
search( &(*l) , &(*end) );
system (p) ;
prin( &(*l) , &(*end) ) ;
printf ("n1 继续编辑 0 结束编辑n") ;
scanf ("%d" , &i) ;

}

}

break;
case 's' : {

i = 1 ;
while (i)
{
searchstr( &(*l) , &(*end) );
getchar();
getchar();
system (p) ;
prin( &(*l) , &(*end) ) ;
printf ("n1 继续搜索 0 结束搜索n") ;
scanf ("%d" , &i) ;

}

}
break;
case 't' : {

coutword ( &(*l) , &(*end) ) ;
getchar() ;

}break;

default : return 0 ;

}

system (p) ;
prin( &(*l) , &(*end) ) ;
printf ("n1 回到编辑菜单 0 结束编辑n") ;
scanf ("%d" , &j) ;
if (j == 1)
system (p) ;
else
return 0 ;

}

return 0 ;
}

//**********实现第一个模块:新建空白文档**********//
int newtext( lnodetype ** l ,lnodetype ** end )
{

printf ( "新文本文件:n" ) ;
int i = 1 ;
char judstr[MAX] ;
lnodetype * temp ;
char jud ;
char * p = "cls" ;

while ( 1 ){

link( &(*l) , &(*end) ) ;
jud = (*end)->date[0] ;

if ( jud == '5' ){ //输入‘5’结束一切

temp = (*end) ;
(*end) = (*end)->prior ;
free (temp) ;

while (1){

printf ( "******************************* out :退出不保存 ****************************n") ;
printf ( "******************************* edit :编辑信息 *****************************n") ;
printf ( "******************************* quit :退出而不存盘 **************************n") ;
printf ( "******************************* qas :退出且存盘 ****************************n") ;
printf ( "******************************* con :继续输入! *****************************n") ;

gets(judstr) ;

if ( !strcmp(judstr , "out") )
{
exitunsave( &(*l) , &(*end) ) ;
return 0 ;
}
else
if ( !strcmp(judstr , "qas") )
{
quitandsave( &(*l) , &(*end) ) ;
return 0 ;
}
else

if ( !strcmp(judstr , "edit") )
{

editmenu (l , end) ;
return 0;

}

system (p) ;

}
return 0 ;

}

}

return 0 ;

}

//**********这个是装入文件的函数**********//
int loadtaxt( char * filename )
{

FILE * fp ;
lnodetype * l ;
char ch ;
int i = 0 ;
char * p = "cls" ;
char judstr[MAX] ;
lnodetype * head ;
lnodetype * end ;

iniatelist ( &head , &end) ;
l = end = head ;

if ( (fp = fopen( filename, "r+")) == NULL ){

printf ("文件不能打开!n") ;
return 0 ;

}

ch = fgetc ( fp ) ;
while ( ch != '@' ){

lnodetype *s ;
s = (lnodetype *)malloc ( sizeof (lnodetype) ) ;
if ( s == NULL ){

printf ("内存空间不够,程序即将退出!") ;
return 0 ;

}

end->next = s ;
s->prior = end ;
end = end->next ;
l->number++ ;
s->quese = l->number ;
printf ("%d行", s->quese ) ;

while ( ch != '#'){

s->date[i] = ch ;
ch = fgetc (fp) ;
i++ ;

}
i = 0;
while ( (end->date[i]>='a' && end->date[i]<='z') ||
(end->date[i]>='A' && end->date[i]<='z') ||
(end->date[i]>='0' && end->date[i]<='9' ) ||
(end->date[i]==' ') )
{

printf ( "%c" , end->date[i] ) ;
i++ ;

}
end->date[i] = '\0' ; //注意在节点的最好加上这个,以让退出保存功能函数知道此节点已结束

printf ( "n" ) ;
i = 0;
ch = fgetc ( fp ) ;

}

fclose (fp) ;

printf ("n文件成功装入!n") ;
while (1){

printf ( "******************************* out :退出不保存 ****************************n") ;
printf ( "******************************* edit :编辑信息 *****************************n") ;
printf ( "******************************* qas :退出且存盘 ****************************n") ;
printf ( "******************************* con :继续输入! *****************************n") ;

scanf("%s",judstr);

if ( !strcmp(judstr , "out") )
{
exitunsave( &l , &end ) ;
return 0 ;
}
else
if ( !strcmp(judstr , "qas") )
{
quitandsave( &l , &end ) ;
return 0 ;
}
else

if ( !strcmp(judstr , "edit") )
{

editmenu (&l , &end) ;
return 0 ;

}

system (p) ;

}

return 0 ;

}

//**********主函数**********//

void main ( void )
{

//iniatelist (&l , &end) ;
//newtext(&l , &end) ;

char filename[MAX] ;
scanf ( "%s" , filename ) ;
loadtaxt( filename ) ;

}
很不容易做的程序!!!
通过编译

Ⅸ 用C语言写一组代码

  • 用C语言编写的代码可以是多个,多文件形式,可以存在多个源文件

  • 用C语言编写的代码生成的可执行文件是一个exe,说白一点就是一个程序

  • 用C语言编程的代码生成的软件,之间可以互相沟通交流的.就像TCP通信编程

  • 用C语言编程的代码,点击我头像,加群.更多精彩.