Author Topic: Curly Problem in Loops  (Read 3519 times)

Offline mert144

  • Single posting newcomer
  • *
  • Posts: 2
Curly Problem in Loops
« on: March 19, 2015, 11:45:46 am »
at least For 15 days we are having problem in loops i am guessing the problem occurs because of Curly( {})  When we write a C program some of the printf statements inside the loop prints the output twice. i am sending a program i write recently and it have the same problem i am awaiting your answers


Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Curly Problem in Loops
« Reply #1 on: March 19, 2015, 01:22:36 pm »
Are you sure that this problem of yours complies with the rule no 1:
Quote
1. This is NOT a general programming board. "How do I write a program that....", "Can anybody teach me how to", "I have this homework", "My program doesn't run and I don't have the slightest idea of why because I'm a C++ newcomer", "What is a compiler", "What does gcc do" is the kind of questions that is FORBIDDEN to ask.
which you have accepted when registering here?
And are you aware that CodeBlocks is NOT a compiler?
If you are sure about the above 2, please state which part of your problem do you think is related to CodeBlocks.

Offline mert144

  • Single posting newcomer
  • *
  • Posts: 2
Re: Curly Problem in Loops
« Reply #2 on: March 21, 2015, 07:51:13 pm »
At first i am sure the problem isnt in code because i test it in another programs and it worked.But codeblocks gives this problem and i am a software engineering student and this is the program which we use in classes thats why i am sending this post to find out if there is any way to fix this problem or is there going to be any update in future which solve my problem
(Sorry for my english if i couldnt explain it properly )
« Last Edit: March 21, 2015, 07:53:23 pm by mert144 »

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Curly Problem in Loops
« Reply #3 on: March 21, 2015, 09:13:12 pm »
Does the problem still occur when you execute '...\bin\debug\1234.exe' from command shell, like running a 'cmd.exe', cd to '...\bin\debug\' and run '1234.exe'?

Offline pirx67

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: Curly Problem in Loops
« Reply #4 on: March 21, 2015, 10:02:35 pm »
Hi mert144,

I'm sorry that I have to disappoint you. From my point of view your program behaves as expected. That what you call a problem / bug stems
from two false assumption that you have made:

1) It is not completely clear to you what the "%c" conversion for scanf() means. Therefore the basis for the unexpected behavior is already
    founded on line 12.
2) You don't observe exactly how many and which keys you need to type to make your program respond with "E is a uppercase character" on a
    new line.

To get a clear view about what really happens you should either debug your program by setting a breakpoint at line 13 and inspect the value of
"x" for each loop run or you may simply put a
Code
printf("*-%02x-*\n", (unsigned char)x);
behind the scanf() call to see what happens.

I think then it should be clear why the program behaves as it does.

Cu,
    pirx67
« Last Edit: March 21, 2015, 10:04:58 pm by pirx67 »