LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2002, 05:07 AM   #1
aizkorri
Member
 
Registered: Feb 2002
Location: Basque Country
Distribution: Fedora 14, Ubuntu 14.04
Posts: 434
Blog Entries: 1

Rep: Reputation: 55
how to call functions


Hello, I've done a simple app that gives some data as output and I have put it in /usr/bin. /usr/bin/writedata

How can I call it from a program?

int main(int argc, char* argv[]) {
writedata;
}

And of course it says that doesn't know what's writedata.
Some Include that I do not know?
Thanks,
regards,
Aizkorri
 
Old 05-22-2002, 05:20 AM   #2
gui10
Member
 
Registered: Mar 2001
Distribution: enigma, slack8
Posts: 677

Rep: Reputation: 30
i think you can just use the system(your_argument) function... like this:

int main() {
system("writedata");
return 0;
}
 
Old 12-20-2017, 07:17 AM   #3
theheapWalker
LQ Newbie
 
Registered: Dec 2017
Posts: 21

Rep: Reputation: Disabled
to call a function in C you use paranthesis after the name of the function.

so a function call would be the following:

writedata();


option 1 ----------------------------------------------------------------

to get items of data from writedata()
you can use the return value.
some thing like:
Code:
   int a_value;

   a_value = writedata();
option 2 ----------------------------------------------------------------

alternatively, have writedata() use a global variable to store
a pointer to a data structure to hold the results from writedata().

global variables are declare before main() in the file.

something like:
Code:
   unsigned int* apointer; /* a variable with global scope declared before main */

   int main(int argc, char* argv[]) {
   writedata;
   }


  writedata()
  {
  apointer = &adatastructure;
  }
if something is not true in this post let me know.


I hope this post aids some-one. considering the threads age.

Last edited by theheapWalker; 12-20-2017 at 12:37 PM. Reason: typing error and tags added
 
Old 12-20-2017, 08:33 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
As it is an old topic, you should use [code] and [/code] tags when you post code in it.
 
Old 12-20-2017, 08:49 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
Meh ... Keep it simple, simple, simple. You must use parentheses so that "C" knows that it's a function and that you're making a function-call here. (Enclose any required parameters in the parentheses, of course, but the parentheses are syntactically required even if there are no arguments.)

Let the function be the master of its own affairs. If it needs a buffer, it should simply malloc() (or "calloc") one, then be sure to dispose of it. Anyone else should be able to call it, and not particularly care how it does its thing.
 
Old 12-20-2017, 12:40 PM   #6
theheapWalker
LQ Newbie
 
Registered: Dec 2017
Posts: 21

Rep: Reputation: Disabled
Thanks NevemTeve for mentioning about the tags.
The post looks better.
 
Old 12-20-2017, 01:17 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
This thread is 15 years old. Within the last day you also resurrected a 16 year old thread.

Please pay attention to the date of the thread before contributing to it. When a thread is this old, there's a very good chance that not a single person who took part in it originally is still an active member of the forum.
 
Old 12-20-2017, 01:20 PM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
@theheapWalker:

You continue to exhibit a pattern of seeking out old posts and replying to them without providing any useful information or questions of your own.

If you have questions of your own please post them to your own thread with proper context. Please see the Site FAQ for guidance in participation on this forum.

If this pattern continues your posting privileges may be suspended.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 09:11 AM
What do you call your remote control? I call mine... RHLinuxGUY General 19 10-18-2004 06:23 AM
help with functions starla827 Programming 1 04-19-2004 02:57 AM
cant get main to call functions, unsure of parameters. c++ calypso_craig Programming 5 10-28-2003 05:47 AM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration