c语言课程设计题目C语言大一课程设计,我们期末考试的作业,大家给个代码啊,要求简单的动画或小游戏,谢谢
c语言课程设计题目 时间:2021-06-03 阅读:(
)
C语言..课程设计参考题目
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define UNKNOWN_CHAR 2
#define DIVISOR_IS_ZERO 3
#define FALSE 0
#define TRUE 1
typedef struct string
{char str;
struct string *next;
}string;
char *GetString();
double GetASResultOf(char * str, int *rank, int *errorNum);
double GetUnitageOf(char * str, int *rank, int *errorNum);
int main()
{
double value;
int rank=0;
int errorNum=TRUE;
char * str;
printf("Please input your arithmetic:
");
str=GetString();
value = GetASResultOf(str, &rank, &errorNum);
if (errorNum==TRUE) printf("The result is: %lf
",value, rank);
else if (errorNum==UNKNOWN_CHAR) printf("char error!
");
else if (errorNum==DIVISOR_IS_ZERO) printf("Divisor could not be 0
");
else printf("Other error
");
getch();
return 0;
}
char *GetString()
{
char *CharToString(string * sHead, int arraySize);
int arraySize=0;
string *s;
string *sHead;
s = (string *)malloc(sizeof(string));
sHead = s;
s->str = getchar();
arraySize++;
while((s->str)!='
')
{
arraySize++;
s->next=(string *)malloc(sizeof(string));
s=s->next;
s->str=getchar();
}
return CharToString(sHead, arraySize);
}
char *CharToString(string * sHead, int arraySize)
{
char *strArray;
string *s=sHead;
int i=0;
strArray = (char*)malloc(arraySize*sizeof(char));
while(i<arraySize)
{
if (s->str=='=' || s->str=='
') break;
if (s->str!=32) strArray[i++]=s->str;
s=s->next;
}
strArray[i]='