China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 07:47
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Help a brother out, there are always problems debugging this C program! Thanks, everyone. View 743 Replies 3
Original Poster Posted 2004-03-13 00:00 ·  中国 河北 保定 联通
初级用户
Credits 216
Posts 27
Joined 2004-01-05 00:00
22-year member
UID 14981
Gender Male
Status Offline
I have 2 questions to ask the experts here,
1 I'm a beginner in C. Today I wrote a program for an exam. When debugging it, there are no syntax errors anymore,
but it still never outputs the correct value.
Could you please point it out for me—where exactly is the mistake?
main()
{int a;
int i=0;
long sum=0;
for (;i<3;i++);
{ scanf("%d",&a);
sum+=a;
}
printf("%d\n",sum);
}
(Input an array and output the sum of the digits)
2 I'm using the XP operating system. When I use TC from the command prompt, why is it that when I switch to drive D (I installed TC on drive D), I can open it, but when executing a program it always can't open the header files, while if I install TC on drive C and run it, this problem does not occur? What's going on?
Thanks for your advice!
Floor 2 Posted 2004-03-13 00:00 ·  中国 四川 成都 联通
初级用户
Credits 154
Posts 14
Joined 2003-12-30 00:00
22-year member
UID 14671
Gender Male
Status Offline
The path is probably not set correctly. Go into Option-------->Directories and take a look.
Floor 3 Posted 2004-03-14 00:00 ·  中国 河北 保定 联通
初级用户
Credits 216
Posts 27
Joined 2004-01-05 00:00
22-year member
UID 14981
Gender Male
Status Offline
Then what about the program above? Where exactly is the mistake?
Floor 4 Posted 2004-03-15 00:00 ·  中国 山东 烟台 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Man, it's a very simple mistake, you're just not careful enough. It's in these two lines, you should be able to find it yourself

for (;i<3;i++);

printf("%d\n",sum);

Besides, this isn't really the place to discuss the C language, so not many people will answer your question.
Forum Jump: