Fedora Linux Support Community & Resources Center
  #1  
Old 20th April 2007, 07:00 AM
manutdateroma Offline
Registered User
 
Join Date: Apr 2007
Posts: 5
Question C programming - use of functions

Hi, ive just started computing and programming in C at uni as a freshmen. I was wondering if someone could explain what is a function and how it works and how it cud be used?
Reply With Quote
  #2  
Old 20th April 2007, 08:10 AM
Reisswolf Offline
Registered User
 
Join Date: May 2006
Posts: 337
Sorry, this question is just too broad to give a meaningful answer. If you narrow it down, you will get better responses.

Surely you can find out what is a function by looking at any number of books and web articles and tutorials on C programming. Programming in C is one such source; you can find many others simply by typing "c programming" into Google.

If there is a particular C function, such as shmget--or even an aspect of C functions, such as function pointers--that is giving you trouble, we can help. Otherwise the question invites the kind of pontification that is neither instructive for the questioner nor satisfying for the respondent.
__________________
Registered user # 441814
Reply With Quote
  #3  
Old 20th April 2007, 09:46 AM
manutdateroma Offline
Registered User
 
Join Date: Apr 2007
Posts: 5
What i meant is how people create their own function or subprogram eg:

int function(int swap1, int swap2);
int main (int argv, int **argc){
int a;
int b;
{some code}
function(a,b)

return(0);
}

int function(int swap1, int swap2){
{some code}
return(function)
}

get the basic idea what im asking?
Reply With Quote
  #4  
Old 20th April 2007, 10:15 AM
Reisswolf Offline
Registered User
 
Join Date: May 2006
Posts: 337
Are you looking to swap two integers? Here are a couple of functions that would do it.





Code:
#include <stdio.h>

/* Declarations */
void swap_with_temp (int*, int*);
void swap_wo_temp (int*, int*);





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

	int x = 5, y = 10;

	swap_with_temp (&x, &y);
	printf ("%d\t%d\n", x, y); /* x is now 10, y is now 5 */

	swap_wo_temp (&x, &y);
	printf ("%d\t%d\n", x, y); /* x is now 5, y is now 10 */

	return 0;

} /* End main () */





void swap_with_temp (int *a, int *b) {

	int temp = *a;
	*a = *b;
	*b = temp;

} /* End swap_with_temp() */





void swap_wo_temp (int *a, int *b) {

	*a = *a + *b;
	*b = *a - *b;
	*a = *a - *b;

} /* End swap_wo_temp () */




I hope this helps.
__________________
Registered user # 441814
Reply With Quote
Reply

Tags
functions, programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not use 3D functions in compiz-fusion ikr1sse Using Fedora 11 6th February 2008 05:00 PM
linux programming vs. windows programming unlovedwarrior Programming & Packaging 11 22nd October 2006 10:14 PM
using CLI app functions, outside of terminal: how to? jsabarese Using Fedora 4 29th August 2006 07:01 PM
Few questions all regarding FC5 functions. Fault EOL (End Of Life) Versions 7 7th August 2006 06:01 AM


Current GMT-time: 18:19 (Thursday, 27-11-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Ebony at Mandarin Oriental, Guangzhou Photos - Frankfurter Alle, Berlin