0

I've written a C program on Linux to calculate the perimeter (I've called the perimeter variable "p") of a square from its side length ("l"). Now I want to use Espeak, a speech synthesis program on Linux to speak the result. I've thought of using the "system" method.

For example, if I want to make Espeak speak "hello" inside my program I would do:

system("espeak -v it Hello");

Now how can I do with the perimeter?

system ("espeak -v it The perimeter is p"); 

doesn't work.

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Jacquelyn.Marquardt
  • 602
  • 2
  • 12
  • 30
  • Probably just need to add quotes around the phrase so it is just one parameter. – Hogan Dec 23 '14 at 16:14
  • 1
    possible duplicate of [pass parameter using system command](http://stackoverflow.com/questions/18014626/pass-parameter-using-system-command) – Paul Roub Dec 23 '14 at 16:14
  • @skrrgwasme loved the "removed fluff" in the edit description. It made my... 10 mintues – bolov Dec 23 '14 at 16:26

2 Answers2

3

You could build the command like in

char command[128];
snprintf(command, sizeof command, "espeak -v it The perimeter is %d", p);

if p is an integer, you should change the format specifier if the type of p is different.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
-1

Thanks to all! I just solved with

#include<stdio.h>
int main()
{
    char command[128];
    int p=40;
    snprintf(command, sizeof(command), "espeak -v it  \"Il perimetro è %d\"",p);
    printf("%s\n",command);
    system(command);
}
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Jacquelyn.Marquardt
  • 602
  • 2
  • 12
  • 30