鱼C论坛

 找回密码
 立即注册
查看: 1825|回复: 2

[已解决]函数赋值问题

[复制链接]
发表于 2022-4-6 14:56:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 英俊男孩建坤 于 2022-4-6 14:57 编辑
  1. #include <stdio.h>

  2. void reverse_translate(int date, int src, int dest, char start_hour[6], char end_hour[6], char date_result[11]){
  3.     int duration = dest - src;
  4.     int date1 = 25 + date;
  5.     int start = 9 + src;
  6.    
  7.     int start_1 = start / 10;
  8.     int start_2 = start - start_1 * 10;
  9.     start_hour[0] = (char)(start_1 + 48);
  10.     start_hour[1] = (char)(start_2 + 48);
  11.     start_hour[2] = ':';
  12.     start_hour[3] = '0';
  13.     start_hour[4] = '0';
  14.    
  15.     int end = start + duration;                        // 这是有问题的地方  
  16.     int end_1 = end / 10;
  17.     int end_2 = end - end_1 * 10;
  18.     end_hour[0] = (char)(end_1 + 48);
  19.     end_hour[1] = (char)(end_2 + 48);
  20.     end_hour[2] = ':';
  21.     end_hour[3] = '0';
  22.     end_hour[4] = '0';

  23.     int month = 4;
  24.     date_result[0] = '2';
  25.     date_result[1] = '0';
  26.     date_result[2] = '2';
  27.     date_result[3] = '2';
  28.     date_result[4] = '-';
  29.     date_result[5] = '0';
  30.     date_result[7] = '-';
  31.     if(date1 > 30){
  32.         date1 -= 30;
  33.         month += 1;
  34.     }
  35.     date_result[6] = (char)(month + 48);
  36.     date_result[8] = (char)((date1 / 10)+48);
  37.     date_result[9] = (char)((date1 - (date1/10) * 10) + 48);
  38. }

  39. int main()
  40. {
  41.    
  42.     char date_result[11];
  43.     char start_hour[6];
  44.     char end_hour[6];
  45.     reverse_translate(1,1,5,start_hour,end_hour,date_result);   // 这是运行方法
  46.     printf("%s\n%s\n%s\n", date_result,start_hour,end_hour);
  47.     return 0;
  48. }
复制代码


reverse_translate 这个函数里头六个参数  前面三个参数输入其他的数字  最后的答案储存在最后三个参数头
为啥这个end_hour会输入 date_result的内容???  求大神指点
最佳答案
2022-4-8 15:55:41
前3个是数,后面3个是数组地址
你调用函数之后,你函数里面的代码就对数组进行操作了,把存储结果写到数组里了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-4-6 17:10:58 | 显示全部楼层
因为因为数组名就是首地址,其实是传入了地址,对地址直接修改
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-4-8 15:55:41 | 显示全部楼层    本楼为最佳答案   
前3个是数,后面3个是数组地址
你调用函数之后,你函数里面的代码就对数组进行操作了,把存储结果写到数组里了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-24 10:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表