Difference: SolutionsToTest2 (1 vs. 2)

Revision 22017-10-24 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"

Solutions to test 2

The sine function

Added:
>
>
Here is the source code of the 3 functions of mysin.

https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTest2/mysin.tar.gz

The mySin function calculated the sin function but this time takes the angles in degrees instead of taking it it radians as the sin function in the math library does. It converts degrees into radians and calls the math library sin function whose result it returns to the caller (callMySin)

The main routine simply calls mySin with an angle of 30°

This is the result when running callMySin:

mySinRes.png

My way of compiling did not work because I did not link the math library into the program (-lm is missing)
The Makefile is part of the mysin.tar.gz package

Command Line Parameters

  1. argc will be 5
  2. argv[0] will be ./myProg, the name of the command
  3. argv[5] is undefined. We have 5 parameters but we start counting from zero!
  4. (argv[3])[1] is the second character of the string "ike" and therefore 'k'. Remember that we start counting from zero!
If we need integer parameters we will have to convert the strings "65" and "35" to integers. The functions atoi or (better) strtol will do this.

To check it the strings are "uli" and "ike", use the string compare function strcmp:

if (strcmp("uli",argv[1]==0) then we found the right string. Alternatively we can say: if (strcmp("uli",argv[1]) as the integer 0 is interpreted as the boolean "false".

Makefiles

CC, CFLAGS, RM, $@ and $^ are all macros

hello and clean are targets

hello.c is a dependency

$(RM) translates into rm -f which removes the listed files but does not print a warning message if one of the listed files does not exists.

$@ is the target and expands into hello

@^ is the dependency and expands into hello.c

 -- Uli Raich - 2017-10-24

Comments

<--/commentPlugin-->
\ No newline at end of file
Added:
>
>
META FILEATTACHMENT attachment="mysin.tar.gz" attr="" comment="" date="1508843451" name="mysin.tar.gz" path="mysin.tar.gz" size="522" user="uli" version="1"
META FILEATTACHMENT attachment="hello.tar.gz" attr="" comment="" date="1508843451" name="hello.tar.gz" path="hello.tar.gz" size="324" user="uli" version="1"
META FILEATTACHMENT attachment="mySinRes.png" attr="" comment="" date="1508843559" name="mySinRes.png" path="mySinRes.png" size="1723" user="uli" version="1"

Revision 12017-10-24 - uli

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="CourseExercises"

Solutions to test 2

The sine function

-- Uli Raich - 2017-10-24

Comments

<--/commentPlugin-->
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback