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 7686195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:25:29+00:00 2026-05-31T19:25:29+00:00

The problem that I have is somehow very specific. I have to implement a

  • 0

The problem that I have is somehow very specific.

I have to implement a sliding window protocol in C over a link. My sender.c file recieves as parameters the speed, delay, and percentage of lost or corrupt files. The data is sent over a link. Since this is a school assignment I do not know the implementation details of the link but, sice the sender and receiver are required to init the link with a port and an ip I guess they are using sockets. Anyway, I’m trying to send to the reciever the connexion parameters in order to use them for timeouts and control flow. I create the data frame payload that sends the 2 ints representing the speed and delay using:

int s = (int)(*speed - '0');
int d = (int)(*delay - '0');
sprintf(t.payload,"%d%d",s,d);

When I print the s and d variables in the sender file the result is 1,1 which is correct. afterwards i’m sending the resulted payloar to the reciever, where payload[0] is assigned to another int variable called speed and payload[1] is assigned to another int called delay. the problem is that here they have the value 49 and not one as they should. I tried using the atoi() functio on them but when I do, the delay is converted successfully to 1 while the speed is converted to 11, which makes no sense. I’ve tried a lot of different ways to make it work, sending them as chars and converting them at the receiving end did not help either.

Any ideas?

PS: sorry for the gigantic post and my english mistakes!

  • 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-31T19:25:30+00:00Added an answer on May 31, 2026 at 7:25 pm

    I assume ‘t’ is struct variable and payload is a character array. You are sending two numbers as char array. Its not possible to convert them back to integers from a char* without some sort of trickery. For example, if your payload is “12345”, then how to extract two correct numbers that you sent from the otherside? All you know is “12345” is a concatenation of 2 numbers. It could be (1,2345) or (12,345) or (1234, 5)…. etc.

    I would suggest you to run the send command twice and receive accordingly.
    Like:

    char str[10]; //a temporary variable
    
    sprint(str,"%d", speed);
    send (.......); //receive just delay alone on the other side
    
    sprint(str,"%d", delay);
    send(........);
    

    An alternative could be insert a character as identifier and tokenize (strtok) when extracting numbers. Like:

    sprint(t.payload, "%dZ%d",speed, delay); //sender side
    /* Here 'Z' is used as a delimiter */
    

    On the receiver side:

    char *tok, *str;
    
    receive(str, ....);
    
    tok=strtok(str,"Z");
    speed = atoi(tok);
    tok=strtok(NULL);
    delay=atoi(tok); 
    

    If you are sending more than 2 numbers, you are take care of strtok and insertion of ‘Z’ accordingly.

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

Sidebar

Related Questions

I have encountered a problem that I have not come accross yet when setting
We have the problem that we have the open project files in our SVN
I have a problem that I have not faced before: It seems that the
i have bought a template that have built in contact form problem is that
I have been Googling a problem that I have with trying to integrate the
This is a really weird problem that I have been having. When I download
I often run into the problem that I have one stream full of data
I frequently run into the problem that I have to preserve state between several
Here is a hum-dinger of a problem that I have not found an answer
problem is that I have to checkout a different branch for every project. and

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.