Notice that in all the input you are getting from the file,
You have an extra " " space after the "," (Comma). So I think that the code should actually be
[_CODE REMOVED_]
Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
>>Here is where I am at with the code:
It would be better for you to follow the instruction strictly:
If the name is in the lastname, firstname format, then it needs to be changed to the firstname lastname format. To do this:
* Copy the firstname to a temporary string
* Add a space to the end of the temporary string
* Add the last name to the end of the temporary string
* Add spaces to the end of the temporary string until it is 15 characters long.
* Copy the temporary string into the passed in string argument
At this point, the name should be in the firstname lastname format. All that remains is to make sure the first letter of each name is upper case and that the others are lower case.
So first check if the string contains a ',' comma. Which can be done by modifying the line 9 to 12 So start you function by line 9 with the following algo in mind:
To Check if the string S contain a comma:
1.[initialization] Set k to 0
2.[Checking comma] Check if the the character at k S[k] is a comma? If yes: The string has a comma. If no: set k to k+1
3.[Checked all?] Determine if you have checked all the characters? If yes: the string have no comma, if no go to next step.
4.[Repeat] Go to step 2 again.
One point to note is that the condition ofwhile should also include to check if the current character is not a null '\0' ( Remember a string is terminated by a null character).
Now as the outcome of line 9-12, you will have to convert your lastname, firstname format to firstname lastname.
Then you simply need to capitalize two characters:
* The one at the very beginning of your string and
* The one just after the first space encountered.
Code the above algo and let us know what happened.
Edit: Though skydiploma was fast than me, I do not really appreciate him giving the OP the code he wanted
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
My appoligies to the OP to divert the topic.
As for the FixName:
First of all you don't need to concatenate the comma but a space.( as per your assignment) as you have to fix it to firstname lastname rather than firstname,lastname
so change the line 9
Next:
Just capatalize n[0] and n[1+strchr(n,' ')] I hope you got why?
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
your first while loops searches for the first alpha char so it can be changed to uppercase.
then the second while loops changes every single remaining character to lowercase (assuming it can be changed), until it finally finds the NULL and quits.
So... instead of continuing that second while until the NULL is found, break out of that second while once another space is found. then keep repeating this pattern of capitalizing the first letter of each word as long as words are found.
note, your code as it stands is extremely fault-intolerant, and i havent even attempted to address that. because it's a whole 'nother subject. but at least youll get the basic operation figured out.
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179