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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:53:03+00:00 2026-06-07T23:53:03+00:00

I need to write a program which gets 4 arguments, the first one a

  • 0

I need to write a program which gets 4 arguments, the first one a string represents a binary file divided to bytes, and the second, third, and fourth (x,y,z) are 3 integers where their sum is 8. each byte has x left bits, y bits after them, and finally z bits. each group represent a number.

I need to print these numbers. For example for x=4, y=3, z=1 and file has 3 bytes:

1010 0001 1 0101 011 1 0010 001 1 the result would be 10 0 1 5 3 1 2 1 1.

I’d like your help with files in C. This is what I wrote:

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

#define  SEEK_SET   0

#define  SEEK_CUR   1

#define  SEEK_END   2

int main(int argc, char** argv) {

    if (argc!=5) {
        printf("enter a file name and 3 integers such that their sum is 8");
        return 0;
    } else {
        FILE* f;
        f=fopen(argv[1], "r");
        if (f==NULL) {
            printf("File %s does not exists \n", argv[1]);
            return 0;
        }

        else {
            int length=0;
            int offset=0;
            fseek(f, 0, SEEK_END);
            length=ftell(f);
            fseek(f, 0, SEEK_SET);

            while (offset < length) {
                int i;
                double sum=0;
                for (i=1; i<= atoi(argv[2]); ++i) {
                    double exponent= atoi(argv[1])- i;
                    sum=getc(f)*pow(2, exponent); 

                }
                printf("%d ", (int)sum);
                sum=0;

                for (i=1; i<= atoi(argv[3]); ++i) {
                    double exponent= atoi(argv[1])- i;
                    sum=fetc(f)*pow(2, exponent);
                }
                printf("%d ", (int)sum);
                sum=0;
                for (i=1; i<= atoi(argv[4]); ++i) {
                    double exponent= atoi(argv[1])- i;
                    sum=getc(f)*pow(2, exponent);
                }
                printf("%d ", (int)sum);
                offset+=8;
            }
            fclose(f);
        }

    }
    return 0;
}

Couple of questions:

  1. I copy the whole argc, **argv from other program which use files. is this Ok? I mean when I enter main c:\stackExchange 5 2 1 would it automatically give 4 to argc and an array of the other parameters as strings? I assumed it does, and wrote the above.
  2. I assumed that getc(f) returns a bit, is this correct?

any other corrections would be gladly welcome.

  • 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-06-07T23:53:06+00:00Added an answer on June 7, 2026 at 11:53 pm

    Regarding your first question, argc is the number of entries in the argv array, i.e. the number of arguments plus one. So for your example command line argc would be 5, with argv containing this:

    argv[0] : "main"
    argv[1] : "c:\\stackExchange"
    argv[2] : "5"
    argv[3] : "2"
    argv[4] : "1"
    argv[5] : NULL
    

    Regarding your second question, getc returns an integer, which if it’s not EOF can be interpreted as a character or a byte depending on if you read text or binary data.

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

Sidebar

Related Questions

I need to write one java program which monitors a folder containing excel sheets
I need to write a program in BSD sockets which behaves like a file
i need to write a program in which main() would read a file(containing some
I need to write a program which reverses the order of the bytes in
I need to write an I2C program which can write data to 32 bit
I need to write a little program in C that parses a string. I
Greetings, I'm trying to write a program in Python which would print a string
I need to write a program which deletes itself while running...How to do in
I need to write a java program which when executed pushes a command into
I need to write a CVS export program which internally use UTF-8 encoding which

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.