Thread: Help of C "Hopefully I will get nice Communication from some Admins"

  1. #31
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kitymarine View Post
    @CommonTater: Okay Guys ..Let's focus on One Line and try to help to correct it properly..I want to know IF shall use Gets for each line to print whatever needed ..for example how can I make up this line with gets instead of printf andscanf Like I used:"Enter zip code: 99990" and how can I use th puts to get the following output at the end of the code:
    The information you entered is:

    Minnie Mouse
    100 Disney Drive
    Orlando, FL 99990
    She is 25 years old.

    We are focused... and you are receiving good advice.

    You are not going to use gets() to print anything... gets() reads a string from the keyboard.

    See the line I've boldfaced, that is actually 3 elements --city, state, and zip-- from your data struct. The only sensible way to format that line is with printf(). Trying to do it with puts() is just going to frustrate you beyond all belief... because, as already explained at least twice, puts() always adds a newline and it only prints strings. Your zip element in the struct is an int.
    Last edited by CommonTater; 06-21-2011 at 09:13 PM.

  2. #32
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    No - scanf() or fgets() READS INPUT, and printf() PRINTS OUTPUT. Keep the "printf()" as your "prompt" to ask the question.

    1. Ask the user to enter a name (output request with "printf()")
    2. Read the input with "fgets()"
    3. Store the input in a string (using the appropriate pointer)
    4. When it comes time to print out the gathered information, use "printf()" again.

  3. #33
    Registered User kitymarine's Avatar
    Join Date
    Jun 2011
    Posts
    18
    I got your points...I got tired I don t know how to change this line:
    printf("Enter name: ",i);
    gets(name.people[i]);
    scanf("%29s",people[i].name);

  4. #34
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is this safer_gets function that your instructor mentioned? If it is as its name says, I would be more keen for you to use it than to get into the habit of using gets. For example, you could post the prototype and a description of what it does.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #35
    Registered User kitymarine's Avatar
    Join Date
    Jun 2011
    Posts
    18
    Even I dont know how to use that safer_gets ..no definition of that one!

  6. #36
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by kitymarine View Post
    Even I dont know how to use that safer_gets ..no definition of that one!
    As I said, find out more about this later. Focus on getting one thing to work the way you want it tonight. Then you should be able to apply this to any strange function you meet. (That is programming - none of us know all the functions, but the trick is understanding how they work so you can sufficiently use any that you meet).

    I went through the code, I think I see your problem.

    You have one loop in your program, which collects data. I think you're trying to force two things to happen at once. (Taking input and printing output.)

    You need to break it into two separate loops - one to collect the data, and then a second to print it all. They are two separate tasks, and should be approached so. You're not supposed to print out the data as you receive it - you're supposed to store it until you're finished taking input and then print it out afterwards.

    Code:
    LOOP_1
    {
    	// Gather user input, and store to the structure array, just like you've been doing.
    }
    
    LOOP_2
    {
    	// Now print out the the information you took from the input and stored
    	//    into the structure array
    }
    If you're tired, take a rest. Don't cram it all in at once, you won't learn effectively that way.

  7. #37
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kitymarine View Post
    I got your points...I got tired I don t know how to change this line:
    printf("Enter name: ",i);
    gets(name.people[i]);
    scanf("%29s",people[i].name);
    First... you need to stop guessing. Get a good book or tutorial on C and go through it page by page. Do all the exercies and review as necessary. Before you start writing programs you need to actually learn C.

    Your gets line will A) return an error because it won't find the variable which you've incorrectly formatted, b) clash with the scanf() that you've left in the program causing the program to ask you twice for each variable.

    The problem here is not that you have an assignment, the problem is that you don't appear to understand your own code -- leading to some doubt that you actually wrote it-- or how the C programming language works.

  8. #38
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I think I have heard gets_s called a safer gets
    gets_s, _getws_s (CRT)

    Tim S.

  9. #39
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Look, it's rather ignorant of you to expect us to read through your assignment description and look over or run your code, and figure out for ourselves where the code produces different output than was asked for. We're not going to waste our time doing that, that's your job.

    You tell us what you're program's doing wrong, and you ask a question about the bit you're stuck trying to fix. I don't know anything about your previous thread, but if you were acting as lazy in there as you are in here then I can guess how it went.

    Edit: Well yeah fine I wrote that based on only reading the first page of this thread. But if it takes longer than that to make a good impression...
    Last edited by iMalc; 06-22-2011 at 01:30 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #40
    Registered User kitymarine's Avatar
    Join Date
    Jun 2011
    Posts
    18
    IMALC ,If you red all comments you gonna realize what's the problem without any freaking bull........!!you dont know ........ about me to accuse me as LAZY...But who has a psychological weakness as YOURS ,HE shows it in forums...With All My respects You are The F....*$*$ Ignorant not me...Moreover,,You can find bunch of people before posting the whole assignment to identify what's the freaking problem....Respect in communication is a Mandatory and it shows the level of education and Humanitarian Behavior...& Finally as an Advise :Get a class about Ethical behavior and Well manners Sir Or Miss

  11. #41
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    @kitymarine:

    Yes, the problem appears to be you. You have no idea how to program in C; and, you appear to be not able to understand what the people are telling you.

    Hint: Mixing scanf() with either fgets() or gets() is not very easy to do.

    I suggest using either scanf() or fgets() not both.
    Note: Using fgets() with sscanf() works very well.

    Links the second one is the method I like; but it might be too much for you.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392


    Tim S.
    Last edited by stahta01; 06-23-2011 at 07:22 PM.

  12. #42
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kitymarine View Post
    IMALC ,If you red all comments you gonna realize what's the problem without any freaking bull........!!you dont know ........ about me to accuse me as LAZY...But who has a psychological weakness as YOURS ,HE shows it in forums...With All My respects You are The F....*$*$ Ignorant not me...Moreover,,You can find bunch of people before posting the whole assignment to identify what's the freaking problem....Respect in communication is a Mandatory and it shows the level of education and Humanitarian Behavior...& Finally as an Advise :Get a class about Ethical behavior and Well manners Sir Or Miss
    Oh boy, do I ever wish I had a dollar for every time I've heard a newbie enter into an established group dynamic and start screaming and hollering --cursing like a drunken salor-- because it's not what they expected....

    Kity, really... you've been given sound advice over and over for more than 40 messages. What part of "Do your own homework" do you not understand?

    No we didn't knuckle down and do your stupid homework for you... nobody in their right mind would. All that does is promote incompetent programmers into the workplace where they affect everyone's performance and don't do their part. Nobody is going to want someone in their programming team who can't play their position properly... and nobody with a lick of sense is going to contribute to it.

    Be honest... that's scoop and poop code you picked up from another student or perhaps on line... THAT is why you don't understand how it works. Believe me, if you'd written it, you'd understand it... And there in lies the problem. You are trying to dunce your way through this with other people's code, demands that others do your work for you and never once making any real effort on your own...

  13. #43
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Your program should include a structure with a tag name of: info. It should contain the following data as members:
    You haven't even fulfilled the most basic of the requirements.

    Any teacher who is teaching you to actually use gets() needs to be fired immediately. Let me guess...you're writing this in Turbo C, aren't you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-31-2009, 04:23 PM
  2. Replies: 46
    Last Post: 08-24-2007, 04:52 PM
  3. Replies: 12
    Last Post: 08-05-2003, 02:16 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM