Notify-Send in C Code

Notify-Send in C Code

How can I call notify-send from C code with a message stored in my string ?

#include <stdlib.h>

int main(int argc, char *argv[]) 
{
   system("mount something somewhere");
   system("notify-send message");
   return 0;
}
0

2 Answers

Just send the string as a parameter to system().

For example:

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

int main(int argc, char *argv[]) 
{
    char command[100], msg[100];

    strcpy(command,"notify-send ");
    strcpy(msg,"\"Hello World\"");
    strcat(command,msg);

    system(command);
    return 0; 
}
#include <stdio.h>

int main(void)
{
    system("notify-send Test \"Hello World\"");
    return 0;
}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.