goldshakil / ElectricalProgrammingCourse2020

This repository is aimed towards sharing and discussing issues about Electrical and Electronics Programming Course
6 stars 1 forks source link

[others] error in scanf #333

Open hsh-notes opened 4 years ago

hsh-notes commented 4 years ago

Hello TA. I don't know why scanf doesn't work. All header files work well. Furthermore, even at the top of the code, scanf worked well. I write the code like this picture. image image

Like the following debug console, I put scanf in the code, but the program ends right away. image

Could you tell me why? There is no error that visual studio tells me. I tried many ways such as restarting the computer, using getchar, but I still could not scan 'x'.

chaudherysharif commented 4 years ago

Please use the fflush function in order to clear the input buffer for next input in character array.

Mohsin Sharif Network Computing Lab Department of Computer Engineering College of Information and Communication Engineering Sungkyunkwan University Jangangu Chunchundong 300 Suwon, Korea, 440-746 Cell: +82-10-9524-7288

On 14-Jun-2020, at 1:38 AM, skkuhi notifications@github.com wrote:

 Hello TA. I don't know why scanf doesn't work. All header files work well. Furthermore, even at the top of the code, scanf worked well. I write the code like this picture.

Like the following debug console, I put scanf in the code, but the program ends right away.

Could you tell me why? There is no error that visual studio tells me. I tried many ways such as restarting the computer, using getchar, but I still could not scan 'x'.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

hsh-notes commented 4 years ago

However, I defined 'x' as char type.

After a few more attempts, I found that only the first scanf was ignored. So if I write scanf twice, the program works only once. Can I write the code like this? image

goldshakil commented 4 years ago

it's an issue in the compiler and has nothing to do with code. from my experience, you can't fix it unless you change your compiler from MICROSOFT VS COMPILER to GCC or GNU. I think you might not know that so just use codeblocks ( it is compatible with visual studio, I tested it) and it has no issues.

hsh-notes commented 4 years ago

Thank you very much for your detailed answer.

  1. Then should I use codeblock instead of visual studio?
  2. Then should I copy the code to Visual studio when I submit it? Or can I submit a C file made of codeblock? (I don't know well about the codeblock...)
goldshakil commented 4 years ago
  1. Yes codeblocks is good enough
  2. Just code in codeblocks. If it works fine just submit your .c file to icampus