Difference between revisions of "CSC270 Hw 10 2016"
(Created page with "--~~~~ ---- <bluebox> You can work on this homework in pairs. You need to provide a text file containing the '''C program''' that solves the problem below. The deadline is 4/...") |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 12:00, 14 April 2016 (EDT) | --[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 12:00, 14 April 2016 (EDT) | ||
---- | ---- | ||
+ | <br /> | ||
<bluebox> | <bluebox> | ||
You can work on this homework in pairs. You need to provide a text file containing the '''C program''' that solves the problem below. | You can work on this homework in pairs. You need to provide a text file containing the '''C program''' that solves the problem below. | ||
The deadline is 4/21/16 at 11:55 p.m. | The deadline is 4/21/16 at 11:55 p.m. | ||
</bluebox> | </bluebox> | ||
+ | <br /> | ||
+ | <br /> | ||
=Problem 1= | =Problem 1= | ||
<br /> | <br /> | ||
− | + | Create the program below and run int. | |
<br /> | <br /> | ||
− | <source lang="C"> | + | ::<source lang="C"> |
/* hw10.c | /* hw10.c | ||
your name here | your name here | ||
Line 21: | Line 24: | ||
int main() { | int main() { | ||
− | char s[ | + | char s[200]; |
//--- get a string of chars --- | //--- get a string of chars --- | ||
Line 34: | Line 37: | ||
</source> | </source> | ||
<br /> | <br /> | ||
− | + | Don't worry if the compiler gives you a warning indicating that gets() is dangerous. It's fine for us right now. This program is the seed for the program you have to write. | |
+ | <br /> | ||
+ | ==Assignment== | ||
+ | <br /> | ||
+ | Write a program that will have the following features: | ||
# it will read a string from the user (as shown above), | # it will read a string from the user (as shown above), | ||
# the string will contain email addresses separated by spaces (one or more spaces between each address) | # the string will contain email addresses separated by spaces (one or more spaces between each address) | ||
Line 40: | Line 47: | ||
# it will skip the first character of each name. For example if the email is '''dthiebaut@smith.edu''', it will print only '''thiebaut.''' | # it will skip the first character of each name. For example if the email is '''dthiebaut@smith.edu''', it will print only '''thiebaut.''' | ||
<br /> | <br /> | ||
+ | |||
==Example of User Interaction== | ==Example of User Interaction== | ||
<br /> | <br /> | ||
− | Enter a list of email addresses: | + | The user input is underline. The user does not press ENTER between the email addresses. Only at the very end of the string (after cnn.com) does the user press ENTER. |
+ | <br /> | ||
+ | Enter a list of email addresses: <u> rdoc@disney.com lgrumpy@disney.com shappy@castle.com nsleepy@smith.edu zbashful@abc.com nsneezy@winter.org ddopey@cnn.com</u> | ||
doc | doc | ||
Line 53: | Line 63: | ||
<br /> | <br /> | ||
+ | Notice how the program took all the names without the first initial from all the email addresses and printed them, one per line. | ||
+ | <br /> | ||
+ | |||
==Assumptions== | ==Assumptions== | ||
<br /> | <br /> | ||
− | * The string entered by the user will never be longer than | + | * The string entered by the user will never be longer than 200 characters. |
* The string entered by the user will contain at least 1 address, and potentially several. | * The string entered by the user will contain at least 1 address, and potentially several. | ||
* All email addresses contain one @-sign | * All email addresses contain one @-sign |
Latest revision as of 14:18, 21 April 2016
--D. Thiebaut (talk) 12:00, 14 April 2016 (EDT)
You can work on this homework in pairs. You need to provide a text file containing the C program that solves the problem below. The deadline is 4/21/16 at 11:55 p.m.
Problem 1
Create the program below and run int.
/* hw10.c your name here this program prompts the user for a string and displays it back. */ #include <stdio.h> int main() { char s[200]; //--- get a string of chars --- printf( "Enter a list of email addresses, separated by spaces: " ); gets( s ); //--- display it back --- printf( "You have entered: %s\n\n", s ); return 0; }
Don't worry if the compiler gives you a warning indicating that gets() is dangerous. It's fine for us right now. This program is the seed for the program you have to write.
Assignment
Write a program that will have the following features:
- it will read a string from the user (as shown above),
- the string will contain email addresses separated by spaces (one or more spaces between each address)
- it will print the name of each person, without the text following the @-sign, and
- it will skip the first character of each name. For example if the email is dthiebaut@smith.edu, it will print only thiebaut.
Example of User Interaction
The user input is underline. The user does not press ENTER between the email addresses. Only at the very end of the string (after cnn.com) does the user press ENTER.
Enter a list of email addresses: rdoc@disney.com lgrumpy@disney.com shappy@castle.com nsleepy@smith.edu zbashful@abc.com nsneezy@winter.org ddopey@cnn.com doc grumpy happy sleepy bashful sneezy dopey
Notice how the program took all the names without the first initial from all the email addresses and printed them, one per line.
Assumptions
- The string entered by the user will never be longer than 200 characters.
- The string entered by the user will contain at least 1 address, and potentially several.
- All email addresses contain one @-sign
Submission
Submit your program on Moodle, as a text file, in the HW 10 section.