CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Copy Variable

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

Copy Variable
PostPosted: Sat Mar 17, 2012 2:18 am     Reply with quote

How to insert a variable from one function to another?
For example:
Code:


func(1){
var_name=10;
var_name+=10;
printf("var_name = %d", var_name);
}

void main(){
unsigned int8 var_name;

while (1){
 func(1);
 }
}

How could I print variable declared in main function, to another one?

Thx in advance!
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Sat Mar 17, 2012 2:44 am     Reply with quote

Basic C. I'd suggest you get a C primer....

Code:

void func(unsigned int8 ival){
//This says 'func', is a function returning nothing (hence 'void', but
//expecting to receive an unsigned int8, which it will refer to internally
//as ival
    ival+=10; //Add ten to the value passed
    printf("main val+10 = %d\n\r", ival);
}

void main(void){
    unsigned int8 int_var; //Call your variables with names that help
    //you remember 'what' they can hold
   
    int_var=20;
    while (1){
      func(int_var);
   }
}

Which will print "main val+10 = 30" taking the value passed _to_ it from main, adding ten, and then printing it.
You need to read a basic book on C, since you can then return a value as well (which can be different), or use global variables (study the dangers of these). This is basic 'programming 101' stuff, not really what this forum is for.

Best Wishes
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sat Mar 17, 2012 4:48 am     Reply with quote

If you give me, some links with this book would be great!
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Mar 17, 2012 5:01 am     Reply with quote

http://www.ccsinfo.com/content.php?page=books

The C Programing Language is the "bible" for C programming.
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Sat Mar 17, 2012 9:40 am     Reply with quote

Seriously, by a primer, I meant a primer. The C programming language, is pretty much written for programmers, and though the book everyone should have, I really would suggest starting with a basic C primer. A Google search will find dozens.

Best Wishes
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sat Mar 17, 2012 11:31 am     Reply with quote

While K&R "The C Programming Language" is the "bible", it can also cure insomnia Shocked Browse through the books at places like Amazon.com and look at the user comments - what works for one person may not for another, but there are some excellent intro books out there - definitely worth the investment.
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group