Tags:
create new tag
view all tags

Solutions to test 2

The sine function

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

Topic attachments
I AttachmentSorted ascending History Action Size Date Who Comment
Unknown file formatgz hello.tar.gz r1 manage 0.3 K 2017-10-24 - 11:10 UnknownUser  
Unknown file formatgz mysin.tar.gz r1 manage 0.5 K 2017-10-24 - 11:10 UnknownUser  
PNGpng mySinRes.png r1 manage 1.7 K 2017-10-24 - 11:12 UnknownUser  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2017-10-24 - uli
 
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