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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:30:28+00:00 2026-05-29T20:30:28+00:00

I am trying to write some simple program to uploading files to my server.

  • 0

I am trying to write some simple program to uploading files to my server. I’ d like to convert binary files to hex. I have written something, but it does not work properly.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static int bufferSize = 1024;
FILE *source;
FILE *dest;

int n;
int counter;

int main() {
    unsigned char buffer[bufferSize];
    source = fopen("server.pdf", "rb");
    if (source) {
        dest = fopen("file_test", "wb");

        while (!feof(source)) {
            n = fread(buffer, 1, bufferSize, source);
            counter += n;
            strtol(buffer, NULL, 2);
            fwrite(buffer, 1, n, dest);
        }
    }
    else {
        printf("Error");
    }
    fclose(source);
    fclose(dest);
}

I use strtol to convert binary do hex. After invoking this code I have still strange characters in my file_test file.

I’ d like to upload a file on server, for example a PDF file. But firstly I have to write a program, that will convert this file to a hex file. I’d like that the length of a line in hex file would be equal 1024. After that, I will upload this file line by line with PL/SQL.

  • 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-29T20:30:30+00:00Added an answer on May 29, 2026 at 8:30 pm

    Your code is fantastically confused.

    It’s reading in the data, then doing a strtol() call on it, with a base of 2, and then ignoring the return value. What’s the point in that?

    To convert the first loaded byte of data to hexadecimal string, you should probably use something like:

    char hex[8];
    
    sprintf(hex, "%02x", (unsigned int) buffer[0] & 0xff);
    

    Then write hex to the output file. You need to do this for all bytes loaded, of course, not just buffer[0].

    Also, as a minor point, you can’t call feof() before you’ve tried reading the file. It’s better to not use feof() and instead check the return value of fread() to detect when it fails.

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

Sidebar

Related Questions

I'm trying to write simple proxy server for some purpose. In it I use
I'm trying to write a simple program that will compare the files in separate
I'm trying to write a simple program to monitor a folder for new files
I'm trying to write a simple program to encrypt and decrypt files using the
I'm trying to write a simple program to play music files with Pygame. My
I have been trying to figure out how to write a simple program to
I'm trying to write a simple pygame program where some boxes move around on
I'm trying to write a simple AppleScript to do some text manipulation on the
I'm trying to write some LINQ To SQL code that would generate SQL like
I'm trying to write a simple program that will receive a string of max

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.