Skip to main content
3 votes
Accepted

Cs50 problem set 2 Initials

There are a few errors in your code that mess up your output. printf("%c",toupper(n[0])); has a serious error. This works for Robert Thompson but not if there was a space before Robert. It would ...
SuperNovaCoder's user avatar
3 votes

Pset2: Initializer list problem

When you have square brackets following the name of a variable, the compiler thinks that you are trying to declare an array of type string with name "s". But that isn't what you want to do with this. ...
NullityNull's user avatar
2 votes

Code i implemented for initials.c

The code is on the right track, but has a few problems. THe code prints the first letter, but it does so inside the for loop. That means that it will do so for every pass through the loop. Except,...
Cliff B's user avatar
  • 69.1k
2 votes

Getting initials from a name

You want hints? Except for the first initial, what character is always before every initial? There are a lot of library functions out there, some that you should look at now, like tolower(), ...
Cliff B's user avatar
  • 69.1k
2 votes

error in initials.c when I use my own functions

The main problem (and probably just a misunderstanding due to lack of further knowledge) is the distinction between a char array char[], and a char pointer char*, which is typedefed as string. Your ...
ChrisG's user avatar
  • 7,396
2 votes
Accepted

pset2: "initials" string usage problem

Parse the string (array of chars) with a for loop. If found a space then print the following char (whether or not you check if that next char is alphabetic is up to you). A little piece of code like ...
NullityNull's user avatar
2 votes
Accepted

Intitials.C Works With Command Line Arguments - How do I make it work with a prompt?

A code too complicated to print the first character in uppercase, the code is inefficient with two loops unnecessary because we know we're looking letters == 0 suppose we introduce a string from the ...
MARS's user avatar
  • 5,179
2 votes

Need help with pset2 Initials!

Your problem is completely structural and lies here: int main(void); The semicolon in this line marks the end of main. (When you learn functions, it would also mark the end of a function signature ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

help with pset2 initials

You should print a character s[i] if it's not space, and either the first character, or preceded by a s[i-1] being a space. You can put that into a single combined condition, and have only one output ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

Pset 2 - Initials help

This /n is not a new line. From the spec (emphasis added): Your program should print the user’s initials (i.e., the first letter of each word in their name) with no spaces or periods, followed by a ...
DinoCoderSaurus's user avatar
2 votes
Accepted

pset 2 initials (less); "expected prompt for input, not output of..."

Did the instructions say to print "What is your full name?" One of the hidden lessons of the first few psets is to write the code exactly to the specification. Any extra or missing prompts, spaces, ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

expected output, but not "MB\n"

(Turns out it is your code that is the problem) You declare an array c[100]. Then you check if s[0] is a space. If it isn't, you put s[0] into c[0]. That's fine. But if it's not a space, you go ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

Access array element by index ERROR

You're right, it's something simple. %s is the placeholder for printing a string. %c is for printing a character. The variable s is for a string, but s[0] is a character, not a string. In this case,...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

Initials: Not printing second initial

The only problem is that your second IF condition is outside the For loop: if (name[i] == ' ') { printf("%c\n", name[i + 1]); so that the blank space is never reached, the solution would be to ...
MARS's user avatar
  • 5,179
1 vote
Accepted

Pset2 Initials Failing Check50

check50 gave me problems like this: :( outputs "MB" for "Milo Banana" \ expected output, but not "MB\u0000\n" This means you are printing the M and the B and then the null character that ...
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

pset2 initials if statement not checking

No, actually, the test condition is almost never true. But I can see why you'd think it is. Funny how it's always in the details! Look very closely at the test code: if ( isspace(name[i]) &...
Cliff B's user avatar
  • 69.1k
1 vote

Pset2 initials problem with printing extra initials

As DinoCoderSaurus helpfully pointed out in the comments, I was trying to use the integer i believing it to have the value of the string length, but I had actually set it to 0 in an earlier line of ...
Thomas Forrest's user avatar
1 vote
Accepted

My Initials program from pset2 is only printing the first 2 characters

Gordon is right \0 or nul is just 00000000 i believe but the space character has a asc|| binary of 00100000 so your searching for the wrong character. I did the same. i would save an ascii web page to ...
masterseeker's user avatar
1 vote

Input names and output the first Initials of the surname and the first name

First, I believe you set this up as a pointer to a char* array of characters. I don't think that's what you desired. Why not just do a char? charc; charb; c = name; b = sname; Second, your ...
James Goldstein's user avatar
1 vote

pset2 initials directory problem

Besides that, make sure you include, int main(void) since you are working in the main function.
Jere's user avatar
  • 37
1 vote
Accepted

Segmentation fault, help with pset2 initials

The syntax is wrong in the second for loop on line 21. Instead of that second for loop, you probably want an if statement to check whether the current character at i is a space and if so, print the ...
Steve Bunting's user avatar
1 vote
Accepted

pset2: Initials - null character troubles

for (int i = 0; name[i+1] != '\0'; i++) is a bad idea, especially with that inner loop. The other case where that is bad is if you input an empty string, which the used get_string function luckily ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

initials: NUL character creating check50 error

If you look carefully, each failed test has a space at the end of the string to be processed. Look at the following code: if (name[i] == ' ' && name[i+1] != ' ') { printf("...
Cliff B's user avatar
  • 69.1k
1 vote

My string.c works only for two word string, how can i make it work on one and three word string?

I will assume you are tackling the 'less comfortable' version of the initials program, whereby you don't have to deal with extraneous whitespace. Your code is currently hard-wired to only print the ...
Steve Bunting's user avatar
1 vote

My string.c works only for two word string, how can i make it work on one and three word string?

Your while loop increments i until a space character is encountered and then you just print out (after capitalizing them) the first character in your string and the character next to the space. You ...
N. Tiwari's user avatar
1 vote

Pset2 Initials.c

It's unclear what you are trying to do with your for loops since 1) it does not advance i (i.e. it will be stuck at 0 since it ends when i<1 which is 0) and 2) you do not reference i anywhere ...
ronga's user avatar
  • 1,415
1 vote
Accepted

My code infinitely loops 'A' and I don't know why

An infinite loop happens if the while condition is never false. Be the computer. What is going to happen if your input is "a miller"? The first space is encountered when i is 1. Let's do the loop: s[...
DinoCoderSaurus's user avatar
1 vote
Accepted

In Pset2 initials, i have a segmentation fault. I really need help!

if (isupper (name)) isupper() takes a single character as input. This is trying to stuff a complete string down its throat, so it chokes and gives a seg fault. If this answers your question, please ...
Cliff B's user avatar
  • 69.1k
1 vote

still practising initials 1

First, a warning about your approach. Even though you say "practising", how will your code handle this example "robert thomas bowden" from the spec? What about "john jacob jinglehammer jones"? The ...
DinoCoderSaurus's user avatar
1 vote

nothing skip[ it gbhh

The while statement in your do/while requires some kind of test, similar to an if statement. You have a for loop setup statement where there should be a test. This is simply not going to compile. ...
Cliff B's user avatar
  • 69.1k

Only top scored, non community-wiki answers of a minimum length are eligible