Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:24:40+00:00 2026-05-27T03:24:40+00:00

okay so i am trying to be more efficient in my programming, by attempting

  • 0

okay so i am trying to be more efficient in my programming, by attempting to pass multiple strings as one char array[100]. I can pass all this info from my client perfectly fine, but am now trying to use substr or strch to remove the values i passed using the char array on the server side.

server will look like this on the other end, with the data passed from the client being stored into memory under vel_rec:

recv(sock, vel_rec, 100, 0);

The program is set up to send some basic numerical data to a threaded server to run computations on and return results. I will most likely be using atoi function to get the integer values back out of the strings and then return a result back to the client. This returned result again will be a character array.

client:

char vel_snd[100], vel_rec[100], char buffer[100]; 
memset(buffer, 0, 99); 
memset(vel_snd, 0, 99); 
memset(vel_rec, 0, 99); 
recv(sock, buffer, 100, 0);
//are we connected? 
cout << "connection status = " << buffer << endl; 
string v0, a, time, space = "\n", stop;  stop = 'g';
while (stop != "x")
{
    cout<<":::Press 'x' then 'enter' at any time to quit:::"<< endl;
    cout<<"enter data? "<< endl;
    cin>>v0;
    stop = v0;
    cout<<"some more data? "<<endl;
    cin>>a;
    stop = a;
    cout<<"even more data? "<<endl;
    cin>>time;
    stop = time;
    v0 += space + a + space + time;
    strcpy(vel_snd, v0.c_str());        
    send(sock,vel_snd,strlen(vel_snd), 0);
    cout<<"Calculating...\n";
    recv(sock, vel_rec, 100, 0);
    cout<<"\nThe data in "<<time<<" seconds will be "<<vel_rec<<endl;
}

okay so this is all fine and dandy, I am sure there exist infinitely better solutions to concatenation of the null characters which I am not even sure will work, just left them there for you to pick over if you can use them on the server side of things. I was attempting to use them to break out my original strings, but without success. I just want the server to receive this char array and copy sections of it into strings. I am assuming this is possible, but if not I could always send multiple char arrays through, it just seems to me that they would get jumbled up on the server if not properly flagged and organized as the data comes in. one in – one out, seems very clean to me and preferable honestly. The use of strings may not even be needed here as well, I just thought it would be better than using int values and converting, when i can just pass them as strings to begin with. Either way, I still need to implement some method of breaking out the values sent to the server from the client and the substr doesn’t want to work with the char array.

I am also incredibly unfamiliar with anything networking and this is my first attempt at it from some tutorials i have seen. I had a 30 min lecture on the subject, with no further explanation other than “it works”. That being said please be constructive in your responses. Hopefully I can learn a bit more than just this, since I plan on implementing something similar in a networked game I am working on. oh and before i forget this is using wsock32.lib.

recap:

[client] 
char array1[100] = string 1 + string 2 + string 3 
server<--char array1 
char array2<--- server 
print 
[server] 
char array1<---client string 1 + string 2 + string 3 
int A = string 1 
int B = string 2 
int C = string 3 
<some math...> 
<char array 2 = itoa  A B C> 
client <--- char array2

Thanks a bunch

Shawn

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:24:41+00:00Added an answer on May 27, 2026 at 3:24 am

    Not sure I understood the question but a simple technique would be to for example, everytime the client enters something it will be newline terminated. Make the and when you have finished inputting data then send that message. When the message is then sent you automatically send the size of the array to the server. So for example on the server side:

    char* temp;
    int i=0;
    nr=read(sd,buf,sizeof(buf));
    temp = strtok(buf,"\n");
    //Got the first token within the string.
    //I'm pretending its an int to switch case the server
    switch(i){
    case 1:
    temp = strtok(NULL,"\n");
    //Get the next token
    printf("CASE 1 with: %s",temp);
    break;
    }
    

    etc…

    I have not tested this code and just wrote it from the back of my mind so if there is faults in syntax I oppologize.

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I'm trying to go for a more pythonic method of doing things. How
Okay, this is a new one. I'm trying to debug my project, which I've
Okay I'm basically day 1 at programming trying to follow Ruby On Rails 3
Okay so I'm trying to make a little gag program that will run away
OKay I don't use actionscript and trying to help my friend edit a flash
okay, so I'm trying to set up a webpage with a div wrapping two
Okay, here's what I'm trying to do: I'm trying to use PHP to develop
Okay, Here is what I'm trying to do... Right now it is compiling but
Okay, I feel like a bit of a 800 pound gorilla trying to thread
Okay, I'm stumped. I'm fiddling with some project settings, trying to start linking against

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.