C 称为对象';strn&x27;这不是一个函数
在编译下面的代码时,我遇到了一个错误 “调用的对象strn不是函数” 厌倦了这个错误!!需要一个解决方案C 称为对象';strn&x27;这不是一个函数,c,arrays,function,compiler-errors,C,Arrays,Function,Compiler Errors,在编译下面的代码时,我遇到了一个错误 “调用的对象strn不是函数” 厌倦了这个错误!!需要一个解决方案 #include <stdio.h> #include <stdlib.h> #include <string.h> #define num 400 int main() { char strn[num]; int count; int a=0,e=0,i=0,o=0,u=0; printf("enter your stri
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define num 400
int main()
{
char strn[num];
int count;
int a=0,e=0,i=0,o=0,u=0;
printf("enter your string!\n");
gets(strn);
for(count=0;count<strlen(strn);count++)
{
if ( strn(count)=='a' )
{
a++;
}
if (strn(count)=='e')
{
e++;
}
#包括
#包括
#包括
#定义数字400
int main()
{
字符strn[num];
整数计数;
int a=0,e=0,i=0,o=0,u=0;
printf(“输入字符串!\n”);
获取(strn);
对于(count=0;count您正在尝试使用strn
,就像它是一个函数一样:strn(count)
您可能正试图访问count
索引处的值,因此应使用strn[count]
此错误非常明显。您已将strn
声明为字符数组
char strn[num];
并将其用作strn(count)
,这是错误的。编译器将其视为一个函数。在代码中,strn(count)
表示对strn()的函数调用,而应使用方括号
带有一个参数count
。您需要的是使用数组订阅
操作符[]
,而不是()
你需要改变
strn(count)
到
也请考虑使用过<代码> GETSH()/代码> .< /P> < P>下标操作符使用符号<代码> []/COD>包围索引。
strn(count)=='a'
你必须写作
strn[count]=='a'
另外,C标准不再支持函数gets
,因为它是一个不安全的函数。请改用fgets
这个程序看起来像
#include <stdio.h>
#include <ctype.h>
#define num 400
int main( void )
{
char strn[num];
char *p;
int a = 0, e = 0, i = 0, o = 0, u = 0;
printf( "Enter your string: " );
fgets( strn, num, stdin );
for ( p = strn; *p != '\0'; ++p )
{
char c = tolower( *p );
switch ( c )
{
case 'a':
a++;
break;
case 'e':
e++;
break;
// and so on...
#包括
#包括
#定义数字400
内部主(空)
{
字符strn[num];
char*p;
int a=0,e=0,i=0,o=0,u=0;
printf(“输入字符串:”);
fgets(strn、num、stdin);
对于(p=strn;*p!='\0';++p)
{
char c=tolower(*p);
开关(c)
{
案例“a”:
a++;
打破
案例“e”:
e++;
打破
//等等。。。
您需要[
和]
而不是(
和)
这里:strn(count)
和使用fgets
而不是get
是危险的,因为它无法防止缓冲区溢出
#include <stdio.h>
#include <ctype.h>
#define num 400
int main( void )
{
char strn[num];
char *p;
int a = 0, e = 0, i = 0, o = 0, u = 0;
printf( "Enter your string: " );
fgets( strn, num, stdin );
for ( p = strn; *p != '\0'; ++p )
{
char c = tolower( *p );
switch ( c )
{
case 'a':
a++;
break;
case 'e':
e++;
break;
// and so on...