![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Inputting text (name) as opposed to an int (ID) - C programmingHere is my problem
I have a league system, however to input a teams score, I select the team via input of an int ID number (int) however I need to enter a the Team name (String) from the array. I cannot get it to work. Can someone please help me Here is the part of the code that does this part: CPP / C++ / C Code:
There is a lot more code to this however this is the relevant part to which I am extremely stuck on. Any help or pointers would be greatly appreciated Last edited by admin : 05-Apr-2007 at 05:41.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: Inputting text (name) as opposed to an int (ID) - C programmingQuote:
2. Show the definition of the array of structs that you are using. 3. Show how you got something into a team name (or how you expect to get something there). In other words: show what you tried. Quote:
No; this shows how you tried to retrieve the information. Since you say that it doesn't work, the relevant part is: how was the information supposed to get into the array in the first place? What is the nature of the struct and the array of structs? Regards, Dave |
|
#3
|
|||
|
|||
Re: Inputting text (name) as opposed to an int (ID) - C programmingCPP / C++ / C Code:
This is where the team info is entered into the array such as the team name CPP / C++ / C Code:
Hope this gives you an idea of how I'm trying to get it to work Davekw |
|
#4
|
|||
|
|||
Re: Inputting text (name) as opposed to an int (ID) - C programmingQuote:
Here is a suggestion: Make a test program that just calls take_team_name a couple of times. Put in debug print statements that allow you to see what the program sees: CPP / C++ / C Code:
You could put print statements in your function also: CPP / C++ / C Code:
My output: Code:
So, your basic concept seems usable. If you get past this point with a couple of teams, then try calling take_team_input(). You can do something similar in that function to see what the heck is happening with your real program. Does it work up to a point and then crash or what? Just saying that "you cannot get it to work", doesn't give us much of a clue. Regards, Dave Foototes: Use of scanf("%ss") is dangerous, since it doesn't protect against a user entering more characters than can be held by the array. Also scanf("%s") doesn't take into account that teams may have spaces in their names. Maybe you don't have any such teams, so that is not a problem with this particular league. But what if some wants to use this program with a league that has "Bad News Bears" or "White Sox", or whatever? Many (most?) experienced programmers would probly recommend fgets() here. You have to do a little more work, but you can make it absolutely safe, and it will accommodate team names with spaces, should that ever become important. |
|
#5
|
|||
|
|||
Re: Inputting text (name) as opposed to an int (ID) - C programmingThank you Dave.
I'm going to try and test all that you mentioned this evening. Once again Thank you |
|
#6
|
||||
|
||||
Re: Inputting text (name) as opposed to an int (ID) - C programmingAlso, please consider you code formatting. See this for ideas to format your code so it's more readable.
__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#7
|
|||
|
|||
Re: Inputting text (name) as opposed to an int (ID) - C programmingThank you again guys
|
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| justifying text with dynamic programming | twigboy | C++ Forum | 6 | 03-Feb-2005 14:30 |
| saving html text | dopee | MySQL / PHP Forum | 1 | 17-Jan-2005 04:15 |
| Inputting program results into a text file? | shouyan | C Programming Language | 2 | 15-Jul-2004 14:04 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The