0

Afer a few false starts,my initials.program provided correct output for all the cases tested by check 50 when I tried them one by one.. But when I tried to check it with check50 it was not even passing one Test even for one case though it was correctly compiled. Later when I added a new line command the following results have been obtained. I appear to be jharvard@appliance (~/Dropbox/pset2): check50 2014.fall.pset2.initials initials.c :) initials.c exists :) initials.c compiles :) outputs "MB" for "Milo Banana" :) outputs "MB" for "milo banana" :( outputs "RTB" for "Robert Thomas Bowden" \ expected output, but not "RT\nB\n" :( outputs "R" for "ROB" \ expected output, but not "R" :( outputs "RTB" for "Robert thomas Bowden" \ expected output, but not "RT\nB\n" https://sandbox.cs50.net/checks/2ca970050c2b4d2a919289d82b48c004 jharvard@appliance (~/Dropbox/pset2): make initials clang -ggdb3 -O0 -std=c99 -Wall -Werror initials.c -lcs50 -lm -o initials jharvard@appliance (~/Dropbox/pset2):going in circles. Space prevents me from listing all the cases that I have played with printf commands.

jharvard@appliance (~/Dropbox/pset2): check50 2014.fall.pset2.initials initials.c :) initials.c exists :) initials.c compiles :) outputs "MB" for "Milo Banana" :) outputs "MB" for "milo banana" :( outputs "RTB" for "Robert Thomas Bowden" \ expected output, but not "RT\nB\n" :( outputs "R" for "ROB" \ expected output, but not "R" :( outputs "RTB" for "Robert thomas Bowden" \ expected output, but not "RT\nB\n" https://sandbox.cs50.net/checks/2ca970050c2b4d2a919289d82b48c004 jharvard@appliance (~/Dropbox/pset2): make initials clang -ggdb3 -O0 -std=c99 -Wall -Werror initials.c -lcs50 -lm -o initials jharvard@appliance (~/Dropbox/pset2):

Checck50 results for initials.c program without printf(ā€œ\nā€); command at the end of the file

jharvard@appliance (~/Dropbox/pset2): check50 2014.fall.pset2.initials initials.c :) initials.c exists :) initials.c compiles :( outputs "MB" for "Milo Banana" \ expected output, but not "MB" :( outputs "MB" for "milo banana" \ expected output, but not "MB" :( outputs "RTB" for "Robert Thomas Bowden" \ expected output, but not "RTB" :( outputs "R" for "ROB" \ expected output, but not "R" :( outputs "RTB" for "Robert thomas Bowden" \ expected output, but not "RTB" https://sandbox.cs50.net/checks/bb175df6547343449c101c4bbf4ede5f jharvard@appliance (~/D Can anybody have any suggestions to remove the remaining error revealed by check50 i.e the unwanted \n output after the first two initials of the name Robert thomas bowden? Honor code prevents me listing my complete program. If anybody needs it to understand my initials.c program listing, I can provide it if they have a reddit account. uma1966

1

If you look at the link it gives you (I'm using the first one that links here), you can see in more detail what it has problems with. It looks like the tests are failing when the initials are 1 and 3 characters long.

In the case of the 1 character test (input is ROB, expecting R\n), your program never adds the \n. With the three character test (input is Robert Thomas Bowden, expecting RTB\n), your program outputs RT\nB. This would indicate you're adding \n after two characters, instead of just "at the end of the string", so I would look into how you're doing that.

| improve this answer | |
  • Thanks for your comment. I have also realised what you are saying. Unfortunately the newline is being added after each ireationif I include a printf("\n"); at the end of my program or printf("%c",name[i+1]);( ith element being the space in the string name) statement at the end of lower to upper case conversion.Hence immediately after second intial is identified \n is added. Hence the program is giving output of RT\nB\n. So far I have not been able to get all the initialslike RTB into a string.uma1966@Melde – uma1966 Feb 14 '15 at 23:54
  • jharvard@appliance (~/Dropbox/pset2): check50 2014.fall.pset2.initials initials.c :) initials.c exists :) initials.c compiles :) outputs "MB" for "Milo Banana" :) outputs "MB" for "milo banana" :) outputs "RTB" for "Robert Thomas Bowden" :) outputs "R" for "ROB" :) outputs "RTB" for "Robert thomas Bowden" sandbox.cs50.net/checks/654a3df437434b1e8a3fc79745f856ba jharvard@appliance (~/Dropbox/pset2): Finally I appear to have succeeded by shifting the new line command down to a proper location @Melde – uma1966 Feb 15 '15 at 7:15
  • stackoverflow.com/questions/1483232/… may be the URL where the char at the end of array char is discussed. Without using this information,I appear to have solved my problem by shifting the new line command to the very bottom of my initials.c program@Melinde – uma1966 Feb 15 '15 at 15:52
0

It is insufficient to just add a newline character after 2 iterations, and the test of 1 and 3 input names proves this. So how to determine the end of the input string? There is a character in C that all strings end in, and it was covered in one of the instructional videos (lecture, section, short, walkthrough). See if you can track that nugget down, and how you could use it in your code. When you see it you'll code it in minutes!

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .