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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:57:07+00:00 2026-06-01T15:57:07+00:00

I want to send an integer as a parameter to the system() function in

  • 0

I want to send an integer as a parameter to the system() function in C, but I haven’t been able to.

I’d like to do this because I have some jpg files which are regularly named as 1.jpg , 2.jpg ... 17.jpg ... ect. The program would assign a randomly chosen value to an integer variable, and open the image file with the same name as the randomly chosen integer by using the system() function.

What I envision:

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

main()
{
    srand(time(NULL));
    i=rand()%30+1; // for example i=17
    system("eog %d.jpg &",i);  //and i want to open 17.jpg here with eog
}   

I know there are too many arguments to the system() function above; I just wanted to give an example of what I wanted.

Is there a way to do this, and if not, how else could I go about doing what I described above?

  • 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-01T15:57:09+00:00Added an answer on June 1, 2026 at 3:57 pm

    You need to convert the integer into a string argument:

    int runSystem(const char *fmt, ...)
    {
        char buffer[4096];
        va_list va;
        va_start(va, fmt);
        vsnprintf(buffer, sizeof(buffer), fmt, va);
        va_end(va);
        return system(buffer);
    }
    
    main()
    {
        srand(time(NULL));
    
        i=1+rand()%30; // for example i=17
    
        runSystem("eog %d.jpg &",i);  //and i want to open 17.jpg here with eog
    
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this to send string or integer but if i want to send
I have a Web Service written in Java. I want to send some strings
I want send a email by Email Class in codeigniter with gmail, but i
I want to send out batch mails using SwiftMail or any similar system. The
I have some code below. This code is a basic push/pop stack class that
I want to send the double quote character to my CreateProcess function. How can
I want to send integer data through textfield to the json server and whatever
I have an array of int which I want to send to other server
I'm using app engine datastore so I have entity like this. @PersistenceCapable public class
In my application i want send a email to one account.in one button click

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.