I can't read info

Hello, I started programing an application in order to send sms through a cell phone connected via USB port, but I get this wierd problem I can't read info, "cin" is not executed exept the first one
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include <iostream>
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <fstream>


using namespace std;


int main()
{
     HANDLE hComm;
     char port_name[5];
     char msg[300];

    cout<<"Modem port:    ";
    cin>>port_name;

hComm = CreateFile( port_name,
                    GENERIC_READ | GENERIC_WRITE,
                    0,
                    0,
                    OPEN_EXISTING,
                    FILE_FLAG_OVERLAPPED,
                    0);
if (hComm == INVALID_HANDLE_VALUE)
   // error opening port; abort
        cout<<"ERROR opening port "<<endl;
    else
        cout<<"SUCCESS"<<endl;

cout<<"Votre message:   "; fgets(msg,300,stdin);
cout<<msg;

cout<<"choisir la liste des numeros:   ";
// le constructeur de ifstream permet d'ouvrir un fichier en lecture
std::ifstream fichier( "fichier.txt" );

    if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
    {
        std::string ligne; // variable contenant chaque ligne lue

        // cette boucle s'arrête dès qu'une erreur de lecture survient
        while ( std::getline( fichier, ligne ) )
        {
            // afficher la ligne à l'écran
            std::cout << ligne << std::endl;
        }
    }

    return 0;
}
"cin" is not executed exept the first one

But there is only one mention of cin (at line 19) in the entire code?
I mean the

fgets(msg,300,stdin);
cout<<msg;
Last edited on
fgets(msg,300,stdin);
is executed (haven't seen this that way before) but cin>>port_name; leaves the end of line in the stream hence fgets() gets an empty line. use ignore() to remove the end of line from the stream.
Last edited on
Topic archived. No new replies allowed.