C/C++ :: Sending Char And Storing It In Vector
Feb 3, 2014
I've got something I'm trying to accomplish, but crashes my program.
I've got my server and client code.
Having the client send a message they type (char Chat[1024]) And the server receiving the chat (char recv_chat[1024]) only to send it to all connected clients again. Which the server sends the recv_chat.
The client receives it (char recv_chat[1024]). This works, and the client gets the right info. However, I'm trying to store it using a vector. I'm sure I've tried any way possible.
Client storing vector pseudo-code:
vector<char*> SaveChat;
int main () {
while (true) {
if (newClientConnected) {
[Code]....
This doesn't work, and crashes my application. I've tried changing the vector to string, const char*, basically anything I can with no avail.
View 8 Replies
ADVERTISEMENT
Apr 9, 2015
Got something like the following. A button that read characters from a thrid party tool and sends it to a listbox. But the contant is not readable.
Code:
void dlg::sendtolistbox() {
unsigned char buf[250];
thirdparty.GetData(buf, len);
Sendmessage(hndl, listboxupdate,0 , (LPARAM)buf);
}
void Mydlg::UpdateListBox(wparam a,laparm b) {
m_listbox.AddString((LPCTSTR)b);
}
The characters show up in the list box as short unreadable characters. like it is chopped.
If i change to : Sendmessage(hndl, listboxupdate,0 , (LPARAM)&buf[15]);
Then I can see readable valid strings of up to 50 characters and then empty unreadable characters afterwards. I tried all kinds of things , including using CString, still did not work.
View 8 Replies
View Related
Oct 29, 2014
Code:
cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())
[Code] .....
View 8 Replies
View Related
Nov 20, 2012
I am unable to understand why is the output for this shows me the address of the stored array.
int main()
{
size_t k= 0 ;
char t[3][100] = { "hi", "di", "fi" } ;
char s[3][100] ;
[Code]....
View 5 Replies
View Related
Oct 31, 2014
I have two classes, Parent and Child, where Parent contains a vector that is used to store instances of Child. When I create an instance of Parent, three instances of Child are also created in Parent's constructor and stored in the vector. I understand that push_back() creates a shallow copy of each Child instance and that Child's destructor is called each time the loop (inside Parent's constructor) iterates. The problem is that because Child's destructor is called each time the local variable child goes out of scope, the memory previously allocated in Child's constructor is destroyed and when Child's destructor is called again later on in the program to get rid of the copy stored in vector, the program crashes. I can fix this by overriding the default copy function or by storing pointers to objects instead of copies of objects. I don't really need to use vectors in this case since I always have three children in one parent but I'm doing this as a learning exercise and would prefer to use vectors.
#include <iostream>
#include <vector>
class Child {
public:
Child() {
std::cout << "child constructor called" << std::endl;
[Code] .....
View 3 Replies
View Related
Jul 13, 2014
I'm having trouble storing a string in a vector.
I keep getting the errors in lines 51-54: no suitable constructor exist to convert from
#include <iostream>
#include <string>
#include <vector>
#include "Movie.h"
using namespace std;
vector <string> movieActors;
void promptForMovie(Movie & myMovie);
[code]....
View 6 Replies
View Related
Jan 10, 2013
I'm trying out the code below; it runs and produces the output I'd expect, but could it lead to undefined behavior?
To test with, I show the key and wait for user input; if the input doesn't match the value, the iterator is stored in the vector.
map<string, string> test;
map<string, string>::iterator it;
vector<map<string, string>::iterator> bad_input;
string input;
test["key 1"] = "value 1";
[Code] ....
I am also interested in knowing if I can use an iterator to walk through the vector? I tried
vector<map<string, string>::iterator>::iterator v_it;
for(v_it = bad_input.begin(); v_it != bad_input.end(); ++v_it)
cout << v_it-> ??
However, I couldn't figure out how to access "first" and "second" using this method. Is it possible to do so?
View 2 Replies
View Related
Jun 6, 2012
I have a hierarchy of Actions (NonMovingActions and MovinActions each with sub-hierarchies). Actions class has an abstract function.
Code:
class Action {
public:
Action(Agent& agent, ...):agent(agent),..{}
virtual ~Action(void);
virtual bool run()=0;
[Code]...
It appears that C++ does not allow this (in Java it was possible). Compiler objects that Action class is abstract (and cannot be instantiated?!)
Code: error C2259: 'Action' : cannot instantiate abstract class
1- May I know what do I not understand here? We cannot refer to sub-class instances with a reference of parent class type?
2- Should I use vector of pointers instead or what?
View 6 Replies
View Related
Feb 19, 2014
Is this possible?
int myfunc( int a, int b, char * c )
char a = "(int)myfunc()";
char b = "(int,int,char*)"
call(a, b, ...) // Function name and return type, params
I want to do function what registers forward what will get callback if the time is right. Basically then i dont need to edit and add extra functions into source files. I just have to include header and use register forward function. If there is anything close to this it would be perfect!
View 5 Replies
View Related
Oct 25, 2013
I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet
Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}
The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.
View 9 Replies
View Related
Dec 1, 2013
This seamed as a simple thing but i am getting something i did not expect: Example:
Code:
vector<char> StrJoin(SubjSeq.size()+ QuerySeq.size());
cout << StrJoin.size()<<"
"; // size x
StrJoin.insert( StrJoin.begin(), QuerySeq.begin(), QuerySeq.end() );
StrJoin.insert( StrJoin.begin(), SubjSeq.begin(), SubjSeq.end() );
cout << StrJoin.size()<<"
"; // x*2
All structures are vector<char>. when i do the above my characters form Query and Subject are copied in my new vector called StrJoin but the size of that vector is twice the size then it should be.
View 3 Replies
View Related
Jun 8, 2013
let say
char temp[8][8];
and you want to make vector of this char
vector<????> boardVec;
View 2 Replies
View Related
Aug 17, 2013
I need to transform a .txt file to a char vector, but how to do it. as much as I could until now been transformed into vector string.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
[Code].....
View 7 Replies
View Related
Feb 3, 2013
I was working on a program which compares sequences of characters, counts the differences between them, and displays them. I had the sequence inputted as a string (into a vector so any number of sequences could be chosen), and then, the way I tried to check the strings for differences, was by converting the string to a (multidimensional) vector of chars:
vector< vector<char> > sequencesC;
for (int a = 0; a < sequenceCount; a++) {
cout << "
Enter sequence " << a+1 <<" name: ";
cin >> sequenceNames[a];
cout << "
[code]....
However, it crashes (as shown above) when I try to set, by a for loop, every char of a multidimensional vector (sequencesC) to the same char of the data vector. Is there any way I can convert the string to a char vector?
View 7 Replies
View Related
Aug 26, 2013
I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:
char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list
[Code] ....
But when I print that, I get a bunch of weird symbols...
View 7 Replies
View Related
Apr 19, 2012
The below code is giving me segment fault during delete [] (*iter) sometimes. Is it not the proper way to delete the vector with char *
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char*> nameList;
for (int i=0;i<1000;++i)
[Code] ....
View 7 Replies
View Related
Jun 9, 2013
I want to save the char[8][8] // fixed size 2 dimension array
to a vector
such as
vector<?????> temp;
is there anyway to approach this?
View 4 Replies
View Related
Sep 16, 2014
why this code works only for file of smaller data. When I try to send for istance a image, the image arrive corrupted.
Client:
//read all file
byte[] vett = File.ReadAllBytes(s);
//read filename
[Code]....
View 11 Replies
View Related
Nov 21, 2013
What's the problem with the following:
Code:
#define K 3;
int max(int a, int b) {
return a>b? a : b;
} int main() {
cout<<max(K, K+3);
return 0;
}
Why is it not allowed, and how is it different from:
Code:
int max(int a, int b) {
return a>b? a : b;
} int main() {
cout<<max(3, 3+3);
return 0;
}
View 3 Replies
View Related
Oct 30, 2013
I have a socket connection already set up, my thing is what would be the best way to send a packet through sockets? My teacher wants us to convert the packet to bits first before we send it. I think he wants something like this:
Code:
struct packet{
int header
int message
int flag
}clientpacket; m
My question is how do we covert this to bits, before sending it. One of my friends said we can create a char[] array the size of the struct as a buffer. will memcpy() change the struct to bits if I copy it to the buffer?
this is how is suppose to look in bits for the header field/column.
Field : header
Field size(bits): 8
data format: Unsigned int
value example: 1
Value in bits: 0000 0001
I am confused, I think I send a structure over the socket but I did not convert it to bits before I sent it .
View 13 Replies
View Related
May 18, 2014
I want to apply program to send matrix from client and server ,and return back a processed matrix ..
How I can do it using UDP ,it was easy to use tcp for that!?
View 3 Replies
View Related
Dec 18, 2014
Verify my Method . I am not getting expected output ..
Code:
int Amount=500;
send(newSocket,Amount,4,0);
close(welcomeSocket);
recv(clientSocket,Amount,4,0);
// Amount= ntohl(Amount);
printf("Data received: %d",atoi(Amount[0]));
View 5 Replies
View Related
Nov 1, 2013
I want to write a program(s) so that the client sits and waits for a scanf to receive an int, then send to server, server then receives the int, processes it, then goes back to sit and wait for new input. to start with, where do i start! server side, or client side? and also what order do i have to go in my program before the loop to set up the socket, and listen? and then what gets looped to keep the connection open and wait for new receive?
View 4 Replies
View Related
Jul 21, 2013
I have a project, to make a program that spams chat programs. I've been trying to figure out how to send a string to an open program such as notepad, or a chat window. I know how to simulate keystrokes but I have yet to figure out or find out any way of sending a string to a program. pseudo code:
int main() {
string a;
int howManyTimes;
cin >> a;
cin >> howManyTimes;
//user enters "pizza"
for(int i = 0; i < howManyTimes; i++) {
//now I want "pizza" to be sent to the program keystroke enter or whatever the correct syntax is sleep
} }
View 1 Replies
View Related
Mar 1, 2013
I am writing some code to send text to a third part software. Basically each sending looks like this:
p << "set terminal eps
";
p << "set output '07.eps'
";
p << "plot '-' using ($1 == 0 ? NaN : $1) with lines linecolor 2 title 'comparison ratio',
'-' using ($1 == 0 ? NaN : $1) with lines title 'comparison ratio'
";
p.send(TOex_ar).send(TOnew_ar);
p << "set terminal wxt 7
";
p << "plot '-' using ($1 == 0 ? NaN : $1) with lines linecolor 2 title 'comparison ratio',
'-' using ($1 == 0 ? NaN : $1) with lines title 'comparison ratio'
";
p.send(TOex_ar).send(TOnew_ar);
Each time I have to change the number "07" and "7";decide to add or not the following parts: "using ($1 == 0 ? NaN : $1)", "with lines", "linecolor 2";and write the title 'comparison ratio' and the name of data to send "TOex_ar" and "TOnew_ar".Since I have to do this kind of thing 50 times in my code, and it is in the form of text, I am wondering whether in C++ we can write a template or function to simplify the program, just to input the changing parts.
View 3 Replies
View Related
Apr 20, 2014
I wanted to make an program which is sending messages to log in and password, but instead of message it gives me "System.Windows.Forms.TextBox, Text: AND HERE MY TEXT I WANTED.
View 9 Replies
View Related