Thread: "system" command and variabile in it

  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    1

    Question "system" command and variabile in it

    Hello,

    I am new here. I have problem with very easy(14 lines) console program. It run console and u need to enter ip address, after this it will send command to printer.


    i tried everything

    Program:
    Code:
    #include<stdio.h>
    
    int main()
    {
    
      char naslov[16] = "000.000.000.000";
    
      printf("Za vnovicni zagon vnesite IP naslov tiskalnika in pritisnite enter:\r\n");
      scanf("%s", &naslov);
      system("curl -k -X PUT https://" %s "/ProductActions/PowerCycle -O '/tmp/pwrc' 2>&1", naslov);
      printf("Tiskalnik z IP naslovom: " % s ", se je ponovno zagnal\r\n", naslov);
    
      return 0;
    
    }
    Thanks for replay!
    Last edited by Salem; 01-06-2021 at 03:02 AM. Reason: Removed crayola

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    You need to print it to a buffer using sprintf.

    Code:
    char buff[1000];
    sprintf(buff,"curl -k -X PUT https://%s/ProductActions/PowerCycle -O '/tmp/pwrc' 2>&1", naslov);
    system(buff);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using the system("clear") command in Vista
    By maverick95 in forum C Programming
    Replies: 15
    Last Post: 08-13-2008, 08:58 PM
  2. Problem with system(""); command!
    By guitarist809 in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2006, 11:39 AM
  3. just a question about the system("cls") command
    By Cmuppet in forum C Programming
    Replies: 8
    Last Post: 08-05-2004, 07:58 PM
  4. Replies: 3
    Last Post: 06-01-2004, 04:29 PM
  5. system("..."); command
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 05-18-2002, 10:59 AM

Tags for this Thread