d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C Programming Homework
Add Reply New Topic New Poll
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Mar 31 2013 02:48pm
i know its a nono to ask for blatently ask for straight programs
but this is all due by tuesday and then study guide for the final


chapter 10


1. Create a program that uses malloc() to allocate a chunk of
memory to hold a string no larger than 80 characters. Prompt
the user to enter his favorite movie. Read his response with
scanf() and assign the data to your newly allocated memory.
Display the user’s favorite movie back to standard output.
2. Using the calloc() function, write a program that reads a user’s
name from standard input. Use a loop to iterate through the
memory allocated counting the number of characters in the
user’s name. The loop should stop when a memory segment is
reached that was not used in reading and storing the user’s
name. (Remember, calloc() initializes all memory allocated.)
Print to standard output the number of characters in the user’s
name.
3. Create a phone book program that allows users to enter names
and phone numbers of friends and acquaintances. Create a
structure to hold contact information and use calloc() to
reserve the first memory segment. The user should be able to
add or modify phone book entries through a menu. Use the
realloc() function to add contiguous memory segments to the
original memory block when a user adds a new phone book
entry.

chapter 12


1. Build a program that creates a macro to calculate the area of a
circle using the formula area = . r2 (area = pie x radius x radius).
In the same program, prompt the user to enter a circle’s radius.
Use the macro to calculate the circle’s area and display the
result to the user.
2. Build a simple program that prompts a user to input the length
and width of a rectangle using a macro to calculate the
perimeter. After retrieving the length and width, pass the data
as arguments in a call to the macro. Use the following
algorithm to derive the perimeter of a rectangle.
Perimeter of a rectangle = 2(length) + 2 (width)
3. Use a similar program design as in Challenge 1 that uses a macro
to calculate total revenue. Use the following formula to
calculate total revenue.
Total revenue = (price)(quantity)
4. Modify the Function Wizard program to include the following
function.
Average cost = total cost / quantity
5. Divide the Cryptogram program from Chapter 7, “Pointers,”
into multiple files using chapter-based concepts.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 31 2013 03:36pm
i highly suggest you drop out not due to your lack of programming logic but from course content overall

Code
1. Create a program that uses malloc() to allocate a chunk of
memory to hold a string no larger than 80 characters. Prompt
the user to enter his favorite movie. Read his response with
scanf() and assign the data to your newly allocated memory.
Display the user’s favorite movie back to standard output.


this is by far the worse fucking thing ive seen ever and it coming from a school? thats even worse. they are basically teaching you to program with buffer overflows in your application. a more logical stance would to malloc 81 * sizeof(char) and then use a file reading function such as fgets to read 80 characters from stdin so that you dont overflow your buffer.

Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Mar 31 2013 04:40pm
Quote (AbDuCt @ 31 Mar 2013 22:36)

this is by far the worse fucking thing ive seen ever and it coming from a school? thats even worse. they are basically teaching you to program with buffer overflows in your application. a more logical stance would to malloc 81 * sizeof(char) and then use a file reading function such as fgets to read 80 characters from stdin so that you dont overflow your buffer.


i guess it's not meant like this ^^
they just didn't mention that you need 81 chars for a length of 80. maybe the school wants that he makes this mistake to learn from it. (if he is unlucky he won't even notice that this may happen...)
i'm sure they will talk about it on tuesday when they see the solution.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 31 2013 05:15pm
Quote (Richter @ Mar 31 2013 06:40pm)
i guess it's not meant like this ^^
they just didn't mention that you need 81 chars for a length of 80. maybe the school wants that he makes this mistake to learn from it. (if he is unlucky he won't even notice that this may happen...)
i'm sure they will talk about it on tuesday when they see the solution.


well they are using scanf with no bound checking anyways. they should be teaching their class to stay away from scanf instead of using it in potentially dangerous situations imo.
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Apr 1 2013 10:51am
I have a program that calculates pi it's simpler and doesn't overflow and is a lot less, but were required to do it specifically like this, which is why half the program's ive given as examples were god aweful
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Apr 2 2013 11:17am
btw my teacher doesnt discuss things like this he assigns and on rare occasions walks around to help us
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 2 2013 11:30am
Quote (Xarai @ Apr 2 2013 01:17pm)
btw my teacher doesnt discuss things like this he assigns and on rare occasions walks around to help us


sounds about right. what, did you think you were paying your teacher to teach?
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Apr 7 2013 12:27pm
oh hardy har har -.-
anyways I passed with a B (our school doesnt use + or - wtf)
anways thank you very very very much abduct you have been the most helpful without directly helping me and I appreciate it
if selftaught is reading... GO FUCK YOURSELF
anyways I don't have any programming classes this term now but I'm still gonna learn some programs on the side so I can properly prep myself for c++, java, or c#
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Apr 9 2013 09:56am
Quote (Xarai @ Apr 7 2013 10:27am)
oh hardy har har -.-
anyways I passed with a B (our school doesnt use + or - wtf)
anways thank you very very very much abduct you have been the most helpful without directly helping me and I appreciate it
if selftaught is reading... GO FUCK YOURSELF
anyways I don't have any programming classes this term now but I'm still gonna learn some programs on the side so I can properly prep myself for c++, java, or c#


Lawl

You mad. But I understand, I'd be mad if I were as stoopid as you too.

GL getting anywhere with programming, I just don't see it happening.
Member
Posts: 23,838
Joined: Feb 18 2009
Gold: 0.01
Apr 9 2013 10:00am
lol
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll