stdin problem

This topic is 4478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I'm rather new at programming, and I'm having a problem with C code. I need to make a program that will send data through USB, and I have the hardware, drivers, and library I need. I modified a sample program that came with the software to send data in small commands instead of large blocks. My problem is, however, how can I modify it to read from a keyboard instead of a file? Here's the piece of my code that I'm having trouble with: (sorry I don't know how to format it correctly) for (index = 0; index < bufcnt; index++) { bytesread = fread(buffer[index], 1, 200, inFile); if (bytesread == 0) { shutdown = TRUE; break; } ... The inFile is declared using a command-line argument, and that works fine. I would like to change it though so that the user can type in a value that would go into buffer[index]. (The bytesread is unimportant). I tried replacing inFile with stdin, but the program doesn't resume when I'm finished typing, even after I pressed ctrl-z and enter a bunch of times. Thanks in advance for your help.

Share on other sites
Your program will block until it's read 200 bytes, just like you told it to.

for (index = 0; index < bufcnt; index++){  if (NULL == fgets(buffer[index], 200, inFile))  {    shutdown = TRUE;    break;  }}

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 9
• 11
• Forum Statistics

• Total Topics
632567
• Total Posts
3007109

×