|登录 |注册

12
返回列表 发新帖
楼主: 小蠢
打印 上一主题 下一主题

谁来帮帮我~C程式!!(急)

[复制链接]

回复 #6 Super-Tomato 的帖子

宅男-兜着走
2009-10-28 09:12 PM
看到腻了~ 还好没人问 hello world 怎么写。

回复 #8 Dhilip89 的帖子

goodhermit95
2009-10-28 09:27 PM
前面为什么要int i?

回复 #12 goodhermit95 的帖子

毛毛小子
2009-10-28 09:48 PM
declare i 呀
如果不预先declare
也可以这样写
for(int i = 0; i <= 100; i++|){
打列******出来
}

也可以
int i;
for( i =0; i <= 100; i++){
bla bla bla
}

回复 #13 毛毛小子 的帖子

宅男-兜着走
2009-10-28 10:40 PM
太正统了~ 某些语言什么都不必 declare。

直接 for(i=0 ; ...;... )

这样就可以了~ 多爽。
Dhilip89
2009-10-29 07:56 AM
原帖由 goodhermit95 于 2009-10-28 09:27 PM 发表
前面为什么要int i?


因为要 declare variable 啊em0051

我在 for loop 外面 declare 的原因是我用的 cl.exe 不支持 ANSI C99 Standard.

  1. #include <stdio.h>

  2. int main()
  3. {

  4.         for (int i = 1; i <= 100; i++)
  5.                 i % 10 == 0 ? printf("\n") : printf("*");

  6.         return 0;
  7. }
复制代码

  1. C:\Users\Dhilip89\Desktop>cl star.c
  2. Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
  3. Copyright (C) Microsoft Corporation.  All rights reserved.

  4. star.c
  5. star.c(6) : error C2065: 'i' : undeclared identifier
  6. star.c(6) : error C2065: 'i' : undeclared identifier
  7. star.c(6) : error C2065: 'i' : undeclared identifier
  8. star.c(7) : error C2065: 'i' : undeclared identifier

  9. C:\Users\Dhilip89\Desktop>cl star.c
  10. Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
  11. Copyright (C) Microsoft Corporation.  All rights reserved.

  12. star.c
  13. star.c(6) : error C2065: 'i' : undeclared identifier
  14. star.c(6) : error C2065: 'i' : undeclared identifier
  15. star.c(6) : error C2065: 'i' : undeclared identifier
  16. star.c(7) : error C2065: 'i' : undeclared identifier
复制代码

  1. #include <stdio.h>

  2. int main()
  3. {
  4.         int i;

  5.         for (i = 1; i <= 100; i++)
  6.                 i % 10 == 0 ? printf("\n") : printf("*");

  7.         return 0;
  8. }
复制代码
  1. C:\Users\Dhilip89\Desktop>cl star.c
  2. Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
  3. Copyright (C) Microsoft Corporation.  All rights reserved.

  4. star.c
  5. Microsoft (R) Incremental Linker Version 9.00.30729.01
  6. Copyright (C) Microsoft Corporation.  All rights reserved.

  7. /out:star.exe
  8. star.obj

  9. C:\Users\Dhilip89\Desktop>star
  10. *********
  11. *********
  12. *********
  13. *********
  14. *********
  15. *********
  16. *********
  17. *********
  18. *********
  19. *********
复制代码

回复 #15 Dhilip89 的帖子

goodhermit95
2009-10-29 09:36 AM
我没注意到他没有(int i = 0)

回复 #16 goodhermit95 的帖子

Dhilip89
2009-10-29 05:38 PM
我在学院才刚刚上到C Programming的课em0031
您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2026-4-27 11:32 AM , Processed in 0.115461 second(s), 21 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部