Thread: Name to Email

  1. #16
    Registered User
    Join Date
    Jun 2013
    Posts
    66
    Quote Originally Posted by Adak View Post
    You'll change your mind the first time you need to hang wall board, and have one arm in a cast and sling.

    It DOES refresh your dictionary of cuss words quite keenly, however.
    I was thinking of programming tasks, actually. I'm not sure how well this practice would translate into the real world.

  2. #17
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    If you've learned about pointers, have you learned about dynamic memory allocation, i.e. malloc/free. That would allow you to read a string into memory without technically using an array.

    Also, many profs provide helper libraries/ for students to use in all there programs. Is there such a library/code for this class, that might provide a function called something like ReadString.

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by sonjared View Post
    I was thinking of programming tasks, actually. I'm not sure how well this practice would translate into the real world.
    I see your point, but here we are with this problem - what can you do to hold the first name, while the last name is input? Having 20 or so individual chars doesn't seem keen.

    If the instructor hasn't given a hint on how this should be done, the students need to press said instructor, for same.

  4. #19
    Registered User
    Join Date
    Jun 2013
    Posts
    19
    Does the first name HAVE TO be given to the program first? If the order could be changed to lastname given first, then firstname, it would be simpler.[/QUOTE]

    Assignment.
    You are to ask a user for first name followed by last name.
    Example:
    Lisa Smith
    Your program should get this data and make an e-mail like this
    [email protected]


    It's stupid, right? He won't let those of us who know more than he has taught to use what we know! He wants us to use a do while loop, I think. And the getchar() function. If you see in my code, I think I am to replicate what I used for the last name (which printed perfectly), for the first name as well. However, when I replicate the do while loop, I get stuck in a static but infinite loop, so whenever I input something, nothing happens, and the program keeps running. This is what the assignment says. While he doesn't say anything about not using arrays, he said we can only use what we have learned by now and the last time I used arrays, he made me redo the assignment. Thank you for al your help

  5. #20
    Registered User
    Join Date
    Jun 2013
    Posts
    66
    what can you do to hold the first name, while the last name is input?
    That's the trick, isn't it? Perhaps not storing more than one character at a time in the first place while doing everything sequentially. Or store the characters in a file rather than the usual array. Removing a common tool makes for some interesting, if convoluted, solutions.

  6. #21
    Registered User
    Join Date
    Jun 2013
    Posts
    19
    We haven't learned about strings either. We are to learn about arrays next week, immediately after the assignment is due. The reason for this unusual teaching method is because we are to learn the entire C (not c#, c++, just basic c) language in a six week summer semester, and we are using a book from the 90s.

  7. #22
    Registered User
    Join Date
    Jun 2013
    Posts
    19
    I think I am to use what I used for the last name for the first name as well. But when I try, it doesn't give me the desired result. If anyone assisting me on this forum can help me replicate my loop, it would be very well appreciated. Thanks!

  8. #23
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It can be done with enough chars to hold that first name, while the last name is input. You may need enough chars for the last name as well, depending on the suffix you need to print. Without the chars, you have no way to store the letters. (There are ways, but not at this entry level, so you can't use them)

    Use a while loop, and put all it's letters, into chars, using getchar(). Then get the last name, and print it, then the underline and first name, and finally the suffix: @whatever.com

    You will need two separate while loops - one for each name. Each will use getchar() and store the letters into separate chars:
    f0,f1,f2,f3,f4,f5,f6 ... f20
    l0, l1,l2,l3,l4,l5,l6 ... l20

    f="first"
    l=el, for "last".
    Last edited by Adak; 06-28-2013 at 02:28 PM.

  9. #24
    Registered User
    Join Date
    Jun 2013
    Posts
    19
    Thank you very much! By while loop, do you mean the standard while loop, or the do-while loop I used for the last name? Also, when I put the printf statemnet for the last name before the one for the first name, the first name is still printed first. Can you explain why that is? Thanks

  10. #25
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    do while is fine, and preferred here.

    SEPARATE THE CHARS for first and last names.

  11. #26
    Registered User
    Join Date
    Jun 2013
    Posts
    19
    Alright, thank you very much. I will attempt to fix it and see if it works

  12. #27
    Registered User
    Join Date
    Jun 2013
    Posts
    19
    I'm sorry to bother you, but it is still not functioning. I created a new variable, assigned it get char, and created a do while loop for the first name and placed it below the last name and the _first letter. However, I do not know what to put in the while statement of the do while, do to the fact that while((l=getchar())!='\n'); has been used for the lastname, and I don't want the user to hit enter twice. And while( (l=getchar())!=' '); also, neither end up printing past the first letter. If possible, can you view my original code and specifically explain what I need to change! Thank you!!

  13. #28
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OK, the first way I suggested -- forget it! It's workable, but the result is so insanely backward, it can't possibly be what your instructor wanted. I don't see any way to make a C program, using nothing but char and int variables, and nothing else. Except this:

    Look at this, and see if it might be what was intended. It uses a FILE variable, but this is as close as I can get atm.

    Code:
    #include<stdio.h>
     
    int main()
    {
       FILE *fp=fopen("firstname.txt", "w");
       int ch;
       
       printf("Enter the first name: \n");
       while((ch=getchar()) != '\n') {  //write first name to file for storage
          fputc(ch, fp);
       }
       fprintf(fp, "@blank.com\n");
       fclose(fp);
       
       printf("Enter the last name: \n");
       while((ch=getchar()) != '\n') {  //print name from keyboard input
          printf("%c",ch);
       }
       putchar('_');   
       fp=fopen("firstname.txt","r");   //print name from file input
       while((ch=fgetc(fp)) != '\n') {
          putchar(ch);
       }
       putchar('\n');
       fclose(fp);
       return 0;
    }

  14. #29
    Registered User
    Join Date
    Jun 2013
    Posts
    19
    Thank you very much! Would this assignment be any easier to complete?

    Assignment.

    You are given a file named data.txt. This file contains first name followed by last name.
    Example:
    Lisa Smith
    Your program should get this data and make an e-mail like
    [email protected]
    And place them in output file named email.txt

    This is the second assignment we are to do, though we have extended time on this, because we haven't learned to deal with files yet. To make our job "easier" (**sarcasm intended) our professor changed it to the assignment I originally showed you, which is due this Monday, where we were to only use loops and get char() functions.

    Thanks once again

  15. #30
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The second assignment would be almost exactly the same. Try it and I believe you'll see that.

    I have a strong dislike for these "work with a blindfold on, and both arms shackled behind your back, and 50 kgs of chain around your feet", type of problems. I'm curious exactly what the instructor wanted on this first program.

    You're welcome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# email
    By mixalissen in forum C# Programming
    Replies: 5
    Last Post: 07-02-2008, 09:53 AM
  2. Email...
    By Junior89 in forum Windows Programming
    Replies: 2
    Last Post: 04-02-2007, 12:56 AM
  3. i got this in an email !
    By blitzkrieg in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 02-07-2003, 06:14 PM
  4. email
    By iain in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-13-2002, 10:57 PM
  5. email in dos
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 01-13-2002, 12:10 PM

Tags for this Thread