CHAR为char *错误信息 [英] Char to Char* Error Message

查看:187
本文介绍了CHAR为char *错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我试图编译我的程序,我得到的字符为char *编译错误...我在C这样做这是我的code:

  INT my_strcmp(字符S1 [],CHAR S2 []){
  INT I;
  对于(i = 0;!I ='\\ 0';我++)
    如果(my_strcmp(S1 [I],S2 [I])== 1)
      返回1;
    否则如果(my_strcmp(S1 [I],S2 [I])== - 1)
      返回-1;
    其他
      返回0;


解决方案

  • S1 的类型为的char *

  • 因此, S1 [I] 的类型字符

  • my_strcmp()预计两个的char * 变量作为参数。<​​/ li>
  • 您传递 S1 [I] (我们刚才说的是一个字符)作为参数之一。

  • 字符的char * 是不同的类型。

Everytime I try to compile my program, I get the Char to Char* compile error... I am doing this in C. This is my code:

int my_strcmp(char s1[], char s2[]) {
  int i;
  for (i=0; i != '\0'; i++)
    if (my_strcmp(s1[i], s2[i]) == 1)
      return 1;
    else if (my_strcmp(s1[i], s2[i]) == -1)
      return -1;
    else
      return 0;

解决方案

  • s1 has type char *
  • Therefore, s1[i] has type char
  • my_strcmp() expects two char * variables as arguments.
  • You pass s1[i] (which we just said is a char) as one of the arguments.
  • char and char * are different types.

这篇关于CHAR为char *错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆