向一个函数传一个数组指针,输出的时候出现乱码,求解答 - 爱问答

(爱问答)

向一个函数传一个数组指针,输出的时候出现乱码,求解答

代码:

#include <stdio.h>

#include <stdlib.h>

void longestCommonPrefix(char **strs){

        for(int i = 0;i < 3; i++)

        {

            for(int j = 0; j < 7;j++)

                printf("%c",strs[i][j]);

            printf(" ");

        }

}

int main()

{

    char s[3][7] = {"flower","flow11","flight"};

    longestCommonPrefix(s);

    return 0;

}


在主函数中的二维数组 s[3][7] 也用指针表达,输出的时就不会出现乱码,而能正确运行了:

向一个函数传一个数组指针,输出的时候出现乱码,求解答

程序如下:

#include <stdio.h>
#include <stdlib.h>
void longestCommonPrefix(char **strs)
 {int i,j;
  for(i = 0;i < 3; i++)
   {
     for(j = 0; j < 7;j++)
       printf("%c",strs[i][j]);
     printf(" ");
   }
 }
int main()
{
  char **s[] = {"flower","flow11","flight"};
  longestCommonPrefix(s);
  getch();
  return 0;
}

下一篇:c语言运行出错

上一篇:为什么英伟达生产的显卡要给华硕,影驰,七彩虹这些公司生产然后卖?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?