A couple of beginner problems, one regarding strcpy and another regarding pointers

A couple of beginner problems, one regarding strcpy and another regarding pointers

This is a discussion on A couple of beginner problems, one regarding strcpy and another regarding pointers within the C Programming forums, part of the General Programming Boards category; Hi i'm pretty new to C and am writing a program for a sports league table. I'm having a couple ...

this code semi works. It works fine if the name i enter has no spaces (eg. ManUtd) However if i enter Man Utd it places Man in teams[i].name and it places Utd in teams[i+1].name for some reason. Any ideas why?

Secondly I have made a function to try and sort an array of structs. I pass in the array of structs of type team, "teams". I call it as follows:

"In this statement, "teams" is of type "pointer to struct declared without a tag", and cannot be converted to "struct declared without a tag". noconvert "(on the line when i am calling sortTable outside the function)

Secondly I get 6 errors saying "In this statement, "teams" has a struct type, but occurs in a context that requires a pointer. <needpointer>" (pointing to different lines of the code)

A lot of questions I know but I'm pretty lost here. Any help greatly appreciated.

scanf() stops reading a string at the first whitespace character. So if you enter "foo bar" then scanf() will first see "foo" and then when you call scanf() again it will see "bar". A much better function for reading in strings is fgets(). You could do something like:

And just for future reference, scanf() can be very picky when taking data.

if you throw it something other than what it is expecting, u will usually cause some really wierd results. A good thing to get to know is fgets and all the get functions in C, they will help you a lot more than scanf, at least they did in my experiences.

You probably have a scanf() call in front of it then. scanf() leaves the \n on the input butter so fgets() interprets it as the user just pressing ENTER without entering anything. Another fgets() call would grab what the user actually typed. There's a whole FAQ on this site about getting input from the user. You might want to read it...

I don't know what that is. Are you using a C++ compiler or have you used a typedef? Seeing your whole code would really have prevented me from having to have asked all the questions I've had to ask in this thread.