求教
程序代码:
#include<stdio.h>
#include<process.h>
#include<math.h>
#include<string.h>
#define COLOR 10
#define N 3
#define null -1
#define A 7
typedef enum
{
False,True
}
bools;
int search(char *source_1,int n,char *source);
void sleep(char *source);
int get(char source[][A],int n);
char source_color[COLOR][A]={"black","brown","red","orange","yellow",
"green","blue","violet","gray","white"};
void main()
{
bools error;
char source[N][A]={"","",""};
int i,total;
char Exit_main='y';
for(i=0;i<N;i++)
{
if(source[i]=="")
{
error=True;
}
}
if(error==True)
{
sleep("Program Error>>Press the return key exit...");
exit(1);
}
do
{
for(i=0;i<N;i++)
{
fflush(stdin);
clearerr(stdin);
printf("Band %d>>",i+1);
gets(source[i]);
if(strcmp(source[i],"Exit>>")==0)
{
sleep("The program execution, press the return key exit...");
exit(0);
}
}
total=get(source,N);
if(total==null)
{
continue;
}
printf("Resistance value>>%g\n",total/pow(10,3));
printf("Whether to continue the operation?>>");
scanf("%s",&Exit_main);
if(Exit_main!='y'&&Exit_main!='n'&&Exit_main!='Y'&&Exit_main!='N')
{
Exit_main='y';
}
}
while(Exit_main=='y'||Exit_main=='Y');
sleep("The program execution, press the return key exit...");
exit(0);
}
void sleep(char *source)
{
char ch;
while(1)
{
printf("%s",source);
fflush(stdin);
clearerr(stdin);
scanf("%c",&ch);
if(ch=='\n')
{
return;
}
}
}
int search(char *source_1,int n,char *source)
{
int i;
bools Exit=False;
for(i=0;i<n;i++)
{
if(strcmp(source_1[i],source)==0)
{
Exit=True;
return (i);
}
}
if(i>=n&&Exit==False)
{
sleep("Error>>Not Color,Press the return key to continue...");
}
return (null);
}
int get(char *source,int n)
{
int one,i;
one=0;
for(i=0;i<n;i++)
{
switch(i)
{
case 0:
one=search(source_color,COLOR,source[i]);
if(one==null)
{
printf("Invalid Color>>%s\n",source[i]);
return null;
}
break;
case 1:
one+=search(source_color,COLOR,source[i]);
if(search(source_color,COLOR,source[i])==null)
{
printf("Invalid Color>>%s\n",source);
return null;
}
break;
case 2:
one=one*(int)pow(10,search(source_color,COLOR,source[i]));
if(search(source_color,COLOR,source[i])==null)
{
printf("Invalid Color>>%s\n",source[i]);
return null;
}
break;
}
}
return (one);
}
为什么出错,错误信息:
--------------------Configuration: 124 - Win32 Debug--------------------
Compiling...
124.cpp
E:\编程\源代码\124.cpp(89) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\编程\源代码\124.cpp(110) : error C2664: 'search' : cannot convert parameter 1 from 'char [10][7]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\编程\源代码\124.cpp(118) : error C2664: 'search' : cannot convert parameter 1 from 'char [10][7]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\编程\源代码\124.cpp(119) : error C2664: 'search' : cannot convert parameter 1 from 'char [10][7]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\编程\源代码\124.cpp(126) : error C2664: 'search' : cannot convert parameter 1 from 'char [10][7]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\编程\源代码\124.cpp(127) : error C2664: 'search' : cannot convert parameter 1 from 'char [10][7]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
124.exe - 1 error(s), 0 warning(s)