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

  • Home
  • SEARCH
  • 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 7553933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:11:57+00:00 2026-05-30T11:11:57+00:00

I wanted to write a C code to zip a file in unix. I

  • 0

I wanted to write a C code to zip a file in unix. I implemented it using system function using UNIX shell command “zip -r filepath”. The zip -r filepath command is working when I execute it directly through UNIX shell.

I have witten the code as below

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int system(const char *zip -r /root/Desktop/hi.txt);
return 0;
}

But I am getting a compile time error saying

"error:expected ‘;’, ‘,’ or ‘)’ before string constant"

syntax system function : http://linux.die.net/man/3/system
int system(const char *command);

How can I fix this? I tried putting the UNIX command in quotations, even though it didn’t work.

  • 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-30T11:11:59+00:00Added an answer on May 30, 2026 at 11:11 am

    When the compiler parses int system(const char *zip -r /root/Desktop/hi.txt); it starts interpreting it as a declaration of something because int is a type and system can very well be an identifier name and because of the parens and the trailing ; it could be interpreted as a function prototype. But then the compiler chokes on -r /root/Desktop/hi.txt because it can’t be parsed as a valid part of the function parameter list.

    You don’t need a declaration, you need a function call, so you drop int and const char *, and the string parameter needs to be quoted:

    ...
    {
    system("zip -r /root/Desktop/hi.txt");
    return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to write a higher order function filter with C++. The code I
I wanted to write a function that would take an object and convert it
I wanted to write something basic in assembly under Windows. I'm using NASM, but
I wanted to write a code in C# to list all the users/groups having
I wanted to write a javascript code that will slide a div in specific
I wanted to write an CUDA code where I could see firsthand the benefits
i seem to write this code over and over again and wanted to see
I'm using constructor injection for the first time and wish to write my code
I wanted to write some code like this: class SomeModel(models.Model): field = models.ForeignKey(SomeOtherModel) def
I wanted to write a code for Catalan Numbers .Catalan Numbers are defined as

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.