haris
haris

Reputation: 2033

Can I return a string from C main() program

I know that C program generally ends with return, where we return the status of the program. However, I want to return a string.

I will be calling the C-executable from a Python script and printing the returned string. Since main can't return a string, How do I do this?

Upvotes: 0

Views: 184

Answers (3)

SwiftMango
SwiftMango

Reputation: 15304

A program never return string. You can output a string to standard output and pipe it in your python code.

Upvotes: 3

SheetJS
SheetJS

Reputation: 22925

the return value must be an integer (in general)

What you can do is have the C program print out results (using printf, for example) and have the python script read the standard output of the process (popen functions that give access to child_stdout)

Upvotes: 6

Sadique
Sadique

Reputation: 22841

No, as per the C Standard main should return an int and not a char * or char [].

(5.1.2.2.1) It (main) shall be defined with a return type of int and with no parameters ... or with two parameters ... or in some other implementation-defined manner

Upvotes: 3

Related Questions