-1
Hello,
Guys, I’m recalling programming (c++) and I took a little project to make one of a program that reads barcodes, records in a vector. Within each code read between characters 24 and 33, has a number that references the Invoice. I need to take out that number and display it along with the code.
Go on, what I’ve already done:
#include<iostream>
#include<string.h>
using namespace std;
string cod[100];
char numnota;
int main()
{
string cod[100];
cout<<"Comece aqui a ler os codigos de barra" << endl;
int i=0;
while(cod[i] != "0"){
cin>>cod[i+1];
i++;
}
i=0;
while(cod[i]!="0")
{
cout << cod[i] << endl;
i++;
}
numnota = cod.substr(24,33);
}
Here:
while(cod[i] != "0"){
should not be:while(cod[i] != \0'){
? If you want a substring thennumnota
should not be declared as a single character, but rather as a string. Since you are not working with the string class maybe you should use:strncpy(numnota, cod+23, 10);
(remembering to correct the statement of a note).– anonimo
Speak, Daniel Thank you for answering. Then the while and the stop condition, when someone type 0, indicates that finished reading the bar codes.I tried to use the function I said, but it didn’t work very well =/
– Guilherme TI
I’m not Daniel, but what you mean to say is that in your barcode, zero is not allowed to exist? As for the function you added the terminator ' 0' at the end?
– anonimo
As you say you are using C++ then it is easier to use the function
substr
class<string>
.– anonimo
In fact, "0" is the stop condition of while, the bar codes will be read normally and when the user type 0, the code closes the reading. I’ll try to use the class you told me
– Guilherme TI